Hello,<br><br><div class="gmail_quote">On Thu, Sep 17, 2009 at 16:05, Daniel Fischer <span dir="ltr">&lt;<a href="mailto:daniel.is.fischer@web.de">daniel.is.fischer@web.de</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;">

Am Donnerstag 17 September 2009 15:56:03 schrieb José Pedro Magalhães:<br>
<div class="im">&gt; Hey Andy,<br>
&gt;<br>
&gt; On Thu, Sep 17, 2009 at 15:40, Andy Gimblett &lt;<a href="mailto:haskell@gimbo.org.uk">haskell@gimbo.org.uk</a>&gt; wrote:<br>
&gt; &gt; Now, some of those algebraic data type types happen to be<br>
&gt; &gt; enumerations; in this case, my idea is to list the constructors, with<br>
&gt; &gt; the rule that each constructor&#39;s position in the list is the Int which<br>
&gt; &gt; gets converted into that constructor.<br>
&gt; &gt;<br>
&gt; &gt; &gt; class Enumerated a where<br>
&gt; &gt; &gt;     constructors :: [a]<br>
&gt; &gt;<br>
&gt; &gt; E.g. here&#39;s a type Bar with three constructors:<br>
&gt; &gt; &gt; data Bar = X | Y | Z deriving (Show)<br>
&gt; &gt; &gt; instance Enumerated Bar where<br>
&gt; &gt; &gt;     constructors = [X, Y, Z]<br>
&gt; &gt;<br>
&gt; &gt; (This is certainly ugly.  Any suggestions?)<br>
&gt; &gt;<br>
&gt; |constructors| is expressible in SYB:<br>
</div>Wow.<br>
<br>
What about<br>
<br>
data Bar = X | Y | Z deriving (Show, Eq, Ord, Enum, Bounded)<br>
<br>
instance Enumerated Bar where<br>
    constructors = [minBound .. maxBound]<br>
<div><div></div><div class="h5"><br>
?<br></div></div></blockquote><div><br>Oh yes, that will certainly work for this very simple datatype. However, one cannot automatically derive instances of |Bounded| for datatypes with non-nullary constructors.<br><br><br>

Cheers,<br>Pedro<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><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>