
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. Admittedly, I'm not sure this is documented. Simon | -----Original Message----- | From: glasgow-haskell-users-bounces@haskell.org [mailto:glasgow-haskell-users- | bounces@haskell.org] On Behalf Of Abraham Egnor | Sent: 23 August 2004 16:02 | To: glasgow-haskell-users@haskell.org | Subject: overzealous defaulting? | | I'm not sure if this is an actual bug, as opposed to an odd instance | of defaulting: | | *GUI.Parser> let printQ q = runQ q >>= print | *GUI.Parser> :t printQ | printQ :: forall a. (Show a) => Q a -> IO () | *GUI.Parser> let p = printQ | *GUI.Parser> :t p | p :: Q Integer -> IO () | | ...but I'm not sure when that would ever be the correct behavior. | | Abe | _______________________________________________ | Glasgow-haskell-users mailing list | Glasgow-haskell-users@haskell.org | http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

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
participants (2)
-
Simon Peyton-Jones
-
Tomasz Zielonka