I am trying to use a la carte data types to define a free monad for template purposes. I wrote some combinators, but I'm stuck. My program continues to diverge, and I do not understand why.
Consider:
math :: Math :<: f => MathExpr a -> Free f ()
blank :: f :<: (Textual :+: Math) => Free f () -> Free (Blank k f) ()
equals :: Free (Math :+: (Blank L Math)) ()
-> Free (Math :+: (Blank R Math)) ()
-> Free Equation ()
Composition (empty mathematics) has the type:
blank . math :: ( f :<: (Textual :+: Math)
, Math :<: f
) => MathExpr a -> Free (Blank k f) ()
Note that f must be both smaller than the mix of Textual and Math, and larger than Math. So the only option for f is math. (I understand that the compiler cannot do this without additional work on my part, if at all)
The problem occurs when I try to evaluate:
test :: Free Equation ()
test = (hoistFree (inj :: Blank 'L Math a -> (Math :+: Blank 'L Math) a)
. blank
. (math :: MathExpr x -> Free Math ())
$ "hi"
)
`equals` (math $ "world")
which apparently loops, tying my processor 100%. The calculation of the results is calculated as follows:
Free (Equation (Free (DirectSum {unDirectSum = Right
GHCi . , -, , , .
, , . ?
: : http://lpaste.net/93471 Data.Domain : http://lpaste.net/93472