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

Johan Holmquist holmisen at gmail.com
Fri Jul 14 07:41:51 EDT 2006


> > Would not "liftM2 (,) [0..] [Sunday .. Saturday]" do the trick?
>
> You mean
>   liftM2 (,) [0..] [January .. December] ?
>     (I chose Months in order to get a sensible example.)

Ah, yes. My mistake.

> I assume that the Bounded class exists in order to stay independent from
> the particular type. With minBound and maxBound you do not rely on whether
> the counting starts on Sunday or Monday if you only want to do something
> for all days.

Now I see. Sure, your code can be used for any bounded type while mine
is specific to Days (or Months).

Well, to achieve the same with cyclic enums I would need yet another
type class to get bounds which do not put any constraints on
exceptions for succ and pred. That would be rather stupid, I think.
Would be better with a dedicated cyclic enum class that do not have
the succ and pred constraints for bounded instances.

> > 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.
>
> You mean  [Monday, Tuesday ... Sunday, Monday] ?

Actually not. No repetitions.

> I also think that there must be a possibility to obtain an empty list.

That would be tricky. Not sure why an empty list must be obtained.

/Johan


More information about the Haskell-Cafe mailing list