unexpected arithmetic sequence and deriving Enum behaviour

Simon Peyton-Jones simonpj at microsoft.com
Mon Jul 3 05:49:34 EDT 2006


| one, and the program compiles. Interestingly, -ddump-deriv doesn't
show
| anything about deriving instances for  Colour, yet, obviously
something
| gets derived.

For me (ghc 6.4.2) it says:
==================== Derived instances ====================
InstInfo: {GHC.Show.Show Foo4.Colour}
  { GHC.Show.showList = GHC.Show.showList__ (GHC.Show.showsPrec 0)
    GHC.Show.showsPrec (_) (Foo4.Red) = GHC.Show.showString "Red"
    GHC.Show.showsPrec (_) (Foo4.Black) = GHC.Show.showString "Black"
    GHC.Show.showsPrec (_) (Foo4.Blue) = GHC.Show.showString "Blue" }
InstInfo: {GHC.Enum.Bounded Foo4.Colour}
  { GHC.Enum.maxBound = Foo4.Blue
    GHC.Enum.minBound = Foo4.Red }

Not very pretty, but definitely not nothing.

| When you run it, it dies with an error message from 'toEnum n' (or
| non-exhaustive pattern if you leave that one out).

That's exactly as specified by the Report. If you look here, 
	http://haskell.org/onlinereport/standard-prelude.html
and search for class Enum, you'll se

	class  Enum a  where
	   ..[snip]...
	-- NOTE: these default methods only make sense for types
	--   that map injectively into Int using fromEnum
	--  and toEnum.
	    enumFrom x       =  map toEnum [fromEnum x ..]

and this is precisely the behaviour you get.

I agree it isn't the behaviour your want.  If every Enum was Bounded,
the enumFrom default method could stop at maxBound.  But Enum and
Bounded are separate classes.

Simon





More information about the Glasgow-haskell-bugs mailing list