[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
Thu Sep 17 10:05:05 EDT 2009
Am Donnerstag 17 September 2009 15:56:03 schrieb José Pedro Magalhães:
> Hey Andy,
>
> On Thu, Sep 17, 2009 at 15:40, Andy Gimblett <haskell at gimbo.org.uk> wrote:
> > Now, some of those algebraic data type types happen to be
> > enumerations; in this case, my idea is to list the constructors, with
> > the rule that each constructor's position in the list is the Int which
> > gets converted into that constructor.
> >
> > > class Enumerated a where
> > > constructors :: [a]
> >
> > 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:
Wow.
What about
data Bar = X | Y | Z deriving (Show, Eq, Ord, Enum, Bounded)
instance Enumerated Bar where
constructors = [minBound .. maxBound]
?
More information about the Haskell-Cafe
mailing list