[Haskell-cafe] How to unify these three types with identical structures into one definition?
Tobias Brandt
to_br at uni-bremen.de
Fri Dec 14 13:08:48 UTC 2018
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,
>
> 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
> deriving (Show,Eq,Ord,Generic)--,Typeable)
>
> 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]
> deriving (Show,Eq,Ord,Generic)
>
> 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)
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20181214/b12c7c6d/attachment.html>
More information about the Haskell-Cafe
mailing list