[Haskell-cafe] Ambiguous type variable with subclass instance (also: is there a better way to do this?)

Andy Gimblett haskell at gimbo.org.uk
Sat Sep 19 14:55:10 EDT 2009


On 17 Sep 2009, at 18:01, Ryan Ingram wrote:

> Here's a way that works more closely to your original version:
>
> instance Enumerated a => Target a where
>    convert n
>        | n >= 0 && n < numConstrs = Just (constrs !! n)
>        | otherwise = Nothing
>     where
>        constrs = constructors
>        numConstrs = length constrs

Aha - that's great, and it works without OverlappingInstances (but  
still with FlexibleInstances and UndecidableInstances - should that  
worry me?)

Just making sure constructors is only referenced once is the key, it  
seems.

Thanks!

-Andy


More information about the Haskell-Cafe mailing list