[Haskell-cafe] Ambiguous type variable with subclass instance
(also: is there a better way to do this?)
haskell at gimbo.org.uk
Thu Sep 17 10:30:14 EDT 2009
On 17 Sep 2009, at 15:21, José Pedro Magalhães wrote:
> > > E.g. here's a type Bar with three constructors:
> > > > data Bar = X | Y | Z deriving (Show)
> > > > instance Enumerated Bar where
> > > > constructors = [X, Y, Z]
> > >
> > > (This is certainly ugly. Any suggestions?)
> > >
> > |constructors| is expressible in SYB:
> What about
> data Bar = X | Y | Z deriving (Show, Eq, Ord, Enum, Bounded)
> instance Enumerated Bar where
> constructors = [minBound .. maxBound]
> 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.
That would be OK in this instance, I think; I'm already dealing with
some of those cases by hand, but there were enough purely nullary ones
that this seemed worth doing.
I don't know if that will work any better with Foo/convert,
Thanks though Daniel - it's good to meet Enum and Bounded.
More information about the Haskell-Cafe