12 May 15:49
M1 + M2 = M3 where both computations in M1 and M2 can be used?
From: sam lee <skynare <at> gmail.com>
Subject: M1 + M2 = M3 where both computations in M1 and M2 can be used?
Newsgroups: gmane.comp.lang.haskell.cafe
Date: 2008-05-12 13:51:17 GMT
Subject: M1 + M2 = M3 where both computations in M1 and M2 can be used?
Newsgroups: gmane.comp.lang.haskell.cafe
Date: 2008-05-12 13:51:17 GMT
Hi.
I want to compose two monads to build another monad where
computations of the two monads can be used inside.
I have:
- MonadTypeInfer : interface (class) for TypeInfer monad
- TypeInfer : a monad that has Map String Type (association of names and types)
- TypeInferT : transformer of above monad
- MonadEval : interface (class) for Eval monad
- Eval : a monad that has Map String Expr (association of names and
code/function body)
- EvalT : transformer of Eval
- tInfer :: Expr -> TypeInfer Type -- given expr, returns type of it
in TypeInfer monad
- eval :: Expr -> Eval Expr -- given expr, returns normalized expr in Eval monad
Problem: in repl, when user defines a function, it should type check
and register type of the function to TypeInfer monad's Map String
Type.
Also, it should store the expression of the function in Eval monad.
I build REPL monad using TypeInferT and EvalT.
> newtype REPL a = REPL { runREPL :: TypeInferT (EvalT IO) a }
> deriving(Monad, Functor, MonadIO, MonadTypeInfer, MonadEval)
> repl :: REPL ()
> repl = do
> input <- prompt ">>> "
(Continue reading)
RSS Feed