<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hello, <br>
</p>
<p>my adhoc solution would be to add a type parameter:</p>
<p>data ExprG a = Var String<br>
| Enclosed String a String<br>
| Prefix a a <br>
| Ternary a String a String a deriving Show<br>
<br>
<br>
type Expr = ExprG (ExprG ())<br>
<br>
type ExprL = ExprG [Expr]<br>
<br>
</p>
<p>Cheers,</p>
<p>Tobias<br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 12/14/18 1:56 PM, ducis wrote:<br>
</div>
<blockquote type="cite"
cite="mid:28219dbc.af97.167acca2714.Coremail.ducis_cn@126.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div
style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial">
<div>Hello,<br>
<br>
Say I have a certain type for parse trees:<br>
data Expr = Var String</div>
| Enclosed String Expr String<br>
| Prefix Expr Expr<br>
| Ternary Expr String Expr String Expr<br>
deriving (Show,Eq,Ord,Generic)--,Typeable)<br>
<div><br>
Then I want a new type where every occurence of "Expr"
definition changed to "[Expr]":<br>
data ExprL = VarL String<br>
</div>
| EnclosedL String [Expr] String<br>
| PrefixL [Expr] [Expr]<br>
| TernaryL [Expr] String [Expr] String [Expr]<br>
deriving (Show,Eq,Ord,Generic)<br>
<div><br>
Sometimes, I also want to use a DList instead of list.<br>
</div>
data ExprD = VarD String<br>
| EnclosedD String (DList Expr) String<br>
| PrefixD (DList Expr) (DList Expr)<br>
| TernaryD (DList Expr) String (DList Expr) String (DList
Expr)<br>
deriving (Show,Eq,Ord,Generic)<br>
<div><br>
They have exactly the same structure, is there a way to unify
the three definitions into one?<br>
Furthurmore, is it possible to generalise the latter two for
all Functors ?<br>
<br>
Thanks,<br>
ducis<br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a>
Only members subscribed via the mailman list are allowed to post.</pre>
</blockquote>
</body>
</html>