{-# OPTIONS_GHC -fglasgow-exts -fallow-overlapping-instances -fallow-undecidable-instances #-}

import MO.Run
import MO.Compile

import Control.Exception (try)

foo = MkMethodInvocation "foo" (ArgList [__"bar"]) (__"eu")
bar = MkMethodInvocation "bar" (ArgList [__"bar"]) (__"eu")
moose = MkMethodCompiled (PureCode (\x -> __(toList x)))

main = do
    i <- fromMethodList [ ("foo", moose) ] :: IO (MethodTable IO)
    let obj_box = MkInvocant
                    ("Aquele que chama", (42 :: Int))
                    (AnyResponder (return i))
    result <- dispatch i obj_box foo
    print $ result

    -- using Control.Exception
    result2 <- try (dispatch i obj_box bar)
    case result2 of
        Left e  -> putStrLn ("yay! ugly exception -> " ++ (show e))
        Right x -> putStrLn "i managed to dispatch without def somehow! :("

    putStrLn "tchau"

