Here&#39;s a way that works more closely to your original version:<br><br>instance Enumerated a =&gt; Target a where<br>   convert n<br>       | n &gt;= 0 &amp;&amp; n &lt; numConstrs = Just (constrs !! n)<br>       | otherwise = Nothing<br>
    where<br>       constrs = constructors<br>       numConstrs = length constrs<br><br>Alternatively:<br><br>instance Enumerated a =&gt; Target a where<br>   convert n<br>       | n &gt;= 0 &amp;&amp; n &lt; numConstrs = Just result<br>
       | otherwise = Nothing<br>    where<br>       numConstrs = length (constructors `asTypeOf` [result])<br>       result = constructors !! n<br><br>However let me warn you that you aren&#39;t going to be happy with this instance when it comes time to use this.  Instead, you probably want one of the following:<br>
<br>defaultConvert :: Enumerated a =&gt; Int -&gt; a<br>defaultConvert n<br>    | n &gt;= 0 &amp;&amp; n &lt; numConstrs = Just (WithEnumerated (constrs !! n))<br>
    | otherwise = Nothing<br>
  where<br>
    constrs = constructors<br>
    numConstrs = length constrs<br><br>(a)<br>instance Target SomeEnumeratedType where convert = defaultConvert<br><br>(b)<br>
newtype WithEnumerated a = WithEnumerated a<br>instance Enumerated a =&gt; Target (WithEnumerated a) where<br>    convert n = WithEnumerated (defaultConvert n)<br><br>OverlappingInstances basically never does what you want in the long run.<br>
<br>  -- ryan<br><br><div class="gmail_quote">On Thu, Sep 17, 2009 at 9:01 AM, Andy Gimblett <span dir="ltr">&lt;<a href="mailto:haskell@gimbo.org.uk">haskell@gimbo.org.uk</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"><br>
On 17 Sep 2009, at 16:50, Daniel Fischer wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Yes, the second appearance of &#39;constructors&#39; is at an unspecified type.<br>
<br>
instance (Enumerated a) =&gt; Target a where<br>
   convert n<br>
      | n &lt; 0     = Nothing<br>
      | otherwise = case drop n constructors of<br>
                       (x:_) -&gt; Just x<br>
                       _ -&gt; Nothing<br>
<br>
would make it compile.<br>
</blockquote>
<br></div>
Neat trick.  It works: thanks!<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
But there&#39;d be a risk that Target is unusable, depending on how instance resolution is<br>
done.<br>
</blockquote>
<br></div>
Unusable?  How so?  Sorry, but I don&#39;t follow...<div><div></div><div class="h5"><br>
<br>
-Andy<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">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><br>