overzealous defaulting?

Tomasz Zielonka t.zielonka at students.mimuw.edu.pl
Mon Aug 23 12:49:23 EDT 2004


On Mon, Aug 23, 2004 at 05:14:32PM +0100, Simon Peyton-Jones wrote:
> The binding
> 	let t = printQ
> falls under the monomorphism restriction.  The Haskell Report would not
> default (Show a), so you might think you'd get an "ambiguous type
> variable" error.  But it's so annoying to get this error for
> 	ghci> show []
> that GHCi is a bit more eager about defaulting ambiguous types: it'll
> apply defaulting if all the constrained classes are standard, and at
> least one of them is numeric *or* is Show, Eq or Ord.
> The *or* part is the non-standard bit.

I feel that it must be somewhat related to this behaviour:

    Prelude> :t show . read
    show . read :: String -> String
    Prelude> (show . read) " 13213 "
    "13213"
    Prelude> (show . read) " 0x10000 "
    "65536"
    Prelude> (show . read) " 10000.0 "
    "*** Exception: Prelude.read: no parse

For some reason GHC defaults to Integer, even when monomorphism
restriction doesn't come into play.

Hugs chooses this funny, but IMHO more correct, type:

    Prelude> :t show . read
    show . read :: (Read a, Show a) => [Char] -> [Char]

Best regards,
Tom

-- 
.signature: Too many levels of symbolic links


More information about the Glasgow-haskell-users mailing list