[Haskell-cafe] Generating random enums

Daniel Fischer daniel.is.fischer at web.de
Sat May 2 16:37:49 EDT 2009

Am Samstag 02 Mai 2009 21:22:26 schrieb Ketil Malde:
> Rahul Kapoor <rk at trie.org> writes:
> >> *Main> toEnum 2
> >
> > ghci does not know what type of enum you want to create from the number
> > 2. Try: toEnum 2 :: DayOfWeek
> >
> > That said, I would expect "toEnum 2" to give an error like: 'Ambiguous
> > type variable `a'....'. So I am not sure why your error message says:
> > '** Exception: Prelude.Enum.().toEnum: bad argument'
> Wild guess: The dread monomorphism restriction uses () as a reasonable
> type, and it only has one element.  Does 'toEnum 0' give '()' as the
> result?

Actually, it seems to be the other way round here:

Prelude> toEnum 2

    Ambiguous type variable `a' in the constraint:
      `Enum a' arising from a use of `toEnum' at <interactive>:1:0-7
    Probable fix: add a type signature that fixes these type variable(s)
Prelude> :set -fno-monomorphism-restriction

<no location info>:
    Warning: -fno-monomorphism-restriction is deprecated: use -XNoMonomorphismRestriction 
or pragma {-# LANGUAGE NoMonomorphismRestriction#-} instead
Prelude> toEnum 2
*** Exception: Prelude.Enum.().toEnum: bad argument

> (I couldn't reproduce it with my version of GHCi - I get the ambigous
> type error message)
> -k

More information about the Haskell-Cafe mailing list