Am Donnerstag 17 September 2009 16:30:14 schrieb Andy Gimblett:
> 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:
> >
> > 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.

Andy's original message hasn't found its way into my inbox yet (neither has 
yours which 
Andy here quotes), so I don't know what Andy wants to do.
From the part you quoted, I drew the conclusion that one thing Andy wanted was 
a more 
elegant way for the case of nullary constructors. For that, SYB is certainly 
overkill.
I haven't looked at your code, I suppose it also does something reasonable in 
the presence 
of non-nullary constructors, in which case the separate treatment of only 
nullary 
constructors would of course be unnecessary.

>
> 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,
> though... :-)

I'll probably understand that when your original message arrives :-)

>
> Thanks though Daniel - it's good to meet Enum and Bounded.
>
> -Andy

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to