[Haskell-cafe] Re: Why is Day and Month bounded?

Johan Holmquist holmisen at gmail.com
Fri Jul 14 06:46:47 EDT 2006


Yes, it would be possible to make ones own class and instantiate from
that. I was just thinking Day and Month should be cyclic per default.


from Henning Thielemann:
> Since the days are cycling, what is more natural about your result
> compared to my one?

I would prefer the one without any repetitions.

> I assume the Bounded instance exists in order to allow loops like
>   liftM2 (,) [0..] [minBound .. (maxBound::System.Time.Month)]

Would not "liftM2 (,) [0..] [Sunday .. Saturday]" do the trick?

Sure there are subtleties, like what should [Monday .. Monday] return, either:
[Monday] or
[Monday, Tuesday ... Sunday]
but to settle for one would be ok to me.

from Malcolm Wallace:
> But how do you feel about the way it breaks some algebraic laws?
>    fromEnum x < fromEnum (succ x)
>    fromEnum x > fromEnum (pred x)

I would take the irresponsible and easy path and just accept it. As
you said, it is not stated that any such relations must hold.

Probably the cleanest approach is the one suggested by Chris Kuklewicz:
Make the cyclings explicit in their own class and escape all surprises
involved in sudden cyclic Enums.

/Johan


More information about the Haskell-Cafe mailing list