[Haskell-beginners] Overflow when reading C types
Patrick Redmond
plredmond at gmail.com
Sun Dec 1 22:30:50 UTC 2013
Prelude> import Foreign.C.Types
Prelude Foreign.C.Types> read "-10" :: CUInt
4294967286
Prelude Foreign.C.Types> read "300" :: CChar
44
This seems like a bug. Shouldn't these result in some kind of read error?
The values expressed as strings are simply not part of the type they
are being parsed into. However, Haskell seems to parse them into an
arbitrarily wide numeric type, and then overflow them down to the
correct size.
What's the rationale here?
More information about the Beginners
mailing list