[Haskell-cafe] How to unify these three types with identical structures into one definition?
ducis_cn at 126.com
Fri Dec 14 12:56:28 UTC 2018
Say I have a certain type for parse trees:
data Expr = Var String
| Enclosed String Expr String
| Prefix Expr Expr
| Ternary Expr String Expr String Expr
Then I want a new type where every occurence of "Expr" definition changed to "[Expr]":
data ExprL = VarL String
| EnclosedL String [Expr] String
| PrefixL [Expr] [Expr]
| TernaryL [Expr] String [Expr] String [Expr]
Sometimes, I also want to use a DList instead of list.
data ExprD = VarD String
| EnclosedD String (DList Expr) String
| PrefixD (DList Expr) (DList Expr)
| TernaryD (DList Expr) String (DList Expr) String (DList Expr)
They have exactly the same structure, is there a way to unify the three definitions into one?
Furthurmore, is it possible to generalise the latter two for all Functors ?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe