[Haskell-cafe] Map constructor in a DSL

Brandon Moore brandon_m_moore at yahoo.com
Tue Oct 26 19:15:41 EDT 2010

You have to figure out here how you can use the function which is the argument to map.

It seems you want to end up with a function of type a -> Evaluator b, to be used as an argument to mapM.

One idea is to add a new constructor Var to represent variables, and something like
evalVar :: Obs b -> a -> Evaluator b
which handles Var by "return"ing the second argument, and everything else as in evalObs.

Then you can evaluate Map like
evalObs (Map f) as = evalObs as >>= mapM (evalVar (f Var))

Except, this won't quit work because the type for evalVar is wrong.

That can be fixed by adding an extra parameter for the variable type:

data Obs varType a where
   Var :: Obs v v
   Map :: (Obs a a -> Obs a b) -> Obs v [a] -> Obs v [b]

or something like that.



More information about the Haskell-Cafe mailing list