Hello, On Thu, Sep 17, 2009 at 16:05, Daniel Fischer <daniel.is.fisc...@web.de>wrote:
> 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 <hask...@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] > > ? > 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. Cheers, Pedro > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe >
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe