Hello,
my adhoc solution would be to add a type parameter:
data ExprG a = Var String
| Enclosed String a String
| Prefix a a
| Ternary a String a String a deriving Show
type Expr = ExprG (ExprG ())
type ExprL = ExprG [Expr]
Cheers,
Tobias
On 12/14/18 1:56 PM, ducis wrote:
Hello,| Enclosed String Expr String
Say I have a certain type for parse trees:
data Expr = Var String
| Prefix Expr Expr
| Ternary Expr String Expr String Expr
deriving (Show,Eq,Ord,Generic)--,Typeable)
| EnclosedL String [Expr] String
Then I want a new type where every occurence of "Expr" definition changed to "[Expr]":
data ExprL = VarL String
| PrefixL [Expr] [Expr]
| TernaryL [Expr] String [Expr] String [Expr]
deriving (Show,Eq,Ord,Generic)
data ExprD = VarD String
Sometimes, I also want to use a DList instead of list.
| EnclosedD String (DList Expr) String
| PrefixD (DList Expr) (DList Expr)
| TernaryD (DList Expr) String (DList Expr) String (DList Expr)
deriving (Show,Eq,Ord,Generic)
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 ?
Thanks,
ducis
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.