module MO.Compile where
import MO.Base
import MO.Util
type MethodName = Atom
class Monad m => Method m a | a -> m where
methodName :: a -> MethodName
methodCompile :: a -> MethodCompiled m
instance Monad m => Method m (AnyMethod m) where
methodName (MkMethod x) = methodName x
methodCompile (MkMethod x) = methodCompile x
data SimpleMethod m
= MkSimpleMethod
{ sm_name :: MethodName
, sm_definition :: MethodCompiled m
}
instance Monad m => Method m (SimpleMethod m) where
methodName = sm_name
methodCompile = sm_definition
data AnyMethod m = forall a. Method m a => MkMethod !a
instance Eq (AnyMethod m) where
MkMethod a == MkMethod b = methodName a == methodName b
instance Ord (AnyMethod m) where
MkMethod a `compare` MkMethod b = methodName a `compare` (methodName b)
instance Show (AnyMethod m) where
show (MkMethod m) = show (methodName m)
newtype MethodCompiled m = MkMethodCompiled { runMC :: Arguments m -> m (Invocant m) }