Relax the restriction on Bounded derivation

Ravi Nanavati ravi at
Tue Apr 17 23:05:15 EDT 2007

On 4/17/07, Neil Mitchell <ndmitchell at> wrote:
> Hi,
> >From Section 10 of the Haskell report, regarding automatic derivation:
> to derive Bounded for a type: "the type must be either an enumeration
> (all constructors must be nullary) or have only one constructor."
> This seems a very artificial restriction - since it allows you to be
> in any one of two camps, but no where in between. It also means that
> Either doesn't derive Bounded, while it could easily do so:
> instance (Bounded a, Bounded b) => Bounded (Either a b) where
>     minBound = Left minBound
>     maxBound = Right maxBound
> So I propose that this restriction be lifted, and that the obvious
> extension be given such that minBound is the lowest constructor with a
> pile of minBounds, and maxBound is the highest constructor with a pile
> of maxBound.

In general, I like the idea of of allowing more flexible derivation of
Bounded, but I'm worried your specific proposal ends up mandating the
derivation of Bounded instances for types that aren't really "bounded" (used
in a deliberately loose sense). Consider the following type:

data Foo = A Char | B Integer | C Int

On some level, there's no real problem in creating a Bounded instance as
follows (which is how I interpret your proposal):

instance Bounded Foo
  minBound  =  A (minBound :: Char)
  maxBound =  C (maxBound :: Int)

On the other hand, there's a real sense in which the type isn't actually
"bounded". For instance, if it was also an instance of Enum, enumerating all
of the values from minBound to maxBound might not terminate. I'm not sure
what to do about the scenario. Should we (unnecessarily) insist that all of
the arguments of all of the constructors be Bounded to avoid this? Should
Bounded more explicitly document what properties the minBound, maxBound and
the type should satisfy? Or something else?

 - Ravi
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Haskell-prime mailing list