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

Daniel Fischer daniel.is.fischer at web.de
Sat Sep 19 15:27:31 EDT 2009


Am Samstag 19 September 2009 20:55:10 schrieb Andy Gimblett:
> 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?)

FlexibleInstances need not worry anybody. They just remove a fairly arbitrary restriction 
of Haskell98 for instance declarations.

UndecidableInstances can be dangerous, but there are perfectly safe things which reauire 
UndecidableInstances, too.

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

Just making sure that every time it is referenced, it is referenced at the correct type.

>
> Thanks!
>
> -Andy



More information about the Haskell-Cafe mailing list