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

Johan Holmquist holmisen at gmail.com
Fri Jul 14 05:14:09 EDT 2006

I'll answer my own post to elaborate:

If Day (and Month) where NOT instances of Bounded, the following would
be possible:

[Monday .. Sunday]
=> should return [Monday, Tuesday ... Saturday, Sunday]
=> but returns []

[Saturday .. Tuesday]
=> should return [Saturday, Sunday, Monday, Tuesday]
=> but returns []

succ Saturday
=> should return Sunday
=> but yields an exception

It would feel natural to be able to get the desired results above. The
Haskell98 report stipulates:

For any type that is an instance of class Bounded as well as Enum, the
following should hold:
 The calls succ maxBound and pred minBound should result in a runtime error.

So, the standard library System.Time respects that and yields
exception for succ Saturday. But if Day was not an instance of Bounded
should it not be legal for succ Saturday to return Sunday?

Now I cannot see the advantage of letting Day (and Month) be instances
of Bounded. The only thing we get out of that is access to functions
maxBound and minBound, but those do not seem useful to me for either
Day or Month.


More information about the Haskell-Cafe mailing list