I ran into exactly the same problem while working on my own toy language :)<br><br>I used a fixed point datatype to solve it as well. This is really the best way, as it lets your expression (or statment) type be a member of functor/foldable/traversable, which is super handy. I made a graph module that lets me convert any fixpointed functor into a graph, which made the rest of that whole process much nicer. If you&#39;re interested in the
graph module, let me know :) <br><br>I think that in an ideal world haskell would have some way of allowing infinite types if you asked for them explicitly (say in the type signature somehow) and then just automatically wrap/unwrap everything with newtypes behind the scenes (well maybe in an ideal world it wouldn&#39;t have to do this either). This wouldn&#39;t change the underlying semantics, but would get rid of alot of messyness.<br>
<br>Infinite types are possible, My toy language infers infinite types just fine :) and I think Ocaml has an option for them, but niether of those have type classes so I&#39;m not sure how compatable the idea is with haskell in general.<br>
<br>- Job<br><br><div class="gmail_quote">On Sun, Aug 2, 2009 at 9:06 PM, Michal D. <span dir="ltr">&lt;<a href="mailto:michal.dobrogost@gmail.com">michal.dobrogost@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">&gt;<br>
&gt;   newtype StmtRec = StmtRec (Stmt [StmtRec])<br>
&gt;<br>
<br>
</div>That&#39;s pretty much were I threw in the towel last night. Except I had<br>
a bunch of places where I had to add the extra constructor statements.<br>
I wish there was a solution that didn&#39;t require these... they really<br>
butcher pattern matching clarity.<br>
<div class="im"><br>
&gt; will do. More generally, you can use<br>
&gt;<br>
&gt;   newtype Fix f = In { out :: f (Fix f) }<br>
&gt;<br>
&gt; and define<br>
&gt;<br>
&gt;   type StmtRec = Fix ([] `O` Stmt)<br>
&gt;<br>
&gt; where  O  denotes composition of functors<br>
&gt;<br>
&gt;   newtype O f g a = O (f (g a))<br>
&gt;<br>
<br>
</div>Thanks for that! This provoked some thought on my part about what<br>
exactly is going on. I think I could solve this if I added some way to<br>
identify that a type parameter is actually referring to the whole<br>
type. Say we had a reserved word &quot;fixpoint&quot; for this. Then we&#39;d have<br>
something like:<br>
<br>
data Stmt x = SIf x x<br>
<br>
then when we actually go to use it, it would be referred to as the type:<br>
<br>
&quot;Stmt [fixpoint]&quot;<br>
<br>
Which would get treated exactly like the data declaration:<br>
<br>
data Stmt = SIf [Stmt] [Stmt]<br>
<br>
I&#39;ll need to add the newtype declaration for the code but I&#39;d be<br>
interested if anyone had further thoughts on this topic. I have an<br>
implementation of both approaches on a toy parser, but I doubt<br>
anyone&#39;s interested in seeing that.<br>
<font color="#888888"><br>
Michal<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>