
| 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. This is all quite reasonable. The defaulting rule says precisely what should happen. When there is an ambiguous constraint, (Show a, Read a) in this case, the defaulting rules say to try Integer and then Int (unless you have a default declaration). In this case Integer works. | Hugs chooses this funny, but IMHO more correct, type: | | Prelude> :t show . read | show . read :: (Read a, Show a) => [Char] -> [Char] It's no more correct, because it's ambiguous. Every call to (show . read) will give rise to an ambiguous constraint, which will be resolved in the same way. GHC just does it a little earlier. Simon

On Tue, Aug 24, 2004 at 08:55:00AM +0100, Simon Peyton-Jones wrote:
| For some reason GHC defaults to Integer, even when monomorphism | restriction doesn't come into play.
This is all quite reasonable. The defaulting rule says precisely what should happen. When there is an ambiguous constraint, (Show a, Read a) in this case, the defaulting rules say to try Integer and then Int (unless you have a default declaration). In this case Integer works.
Forgive me, I ask questions which are answered very clearly in the report (modulo the extended defaulting mechanism in GHC, but that was already explained in your previous message). Best regards, Tom -- .signature: Too many levels of symbolic links
participants (2)
-
Simon Peyton-Jones
-
Tomasz Zielonka