You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
instanceASTBuilderASTwhere
add =Add
mul =Mul
lit =LitinstanceASTBuilder (UnionMAST) where
add l r = mrgReturn $Add l r
mul l r = mrgReturn $Mul l r
lit v = mrgReturn $Lit v
Suppose we have a type:
Consider how to construct a value of this type. To construct the value
(a + b) * (c + d)
, we may have to write:This is ridiculously verbose.
A better way to construct this is to provide a type class that constructs an
AST
or aUnionM AST
in a unified way:and implement the following two instances:
Then we can construct
(a + b) * (c + d)
byas expected.
This can be done with Template Haskell. It may be a good idea to have a way to configure the function names to avoid name clash.
The text was updated successfully, but these errors were encountered: