[Haskell-cafe] A new form of newtype
jmillikin at gmail.com
Tue Dec 8 19:58:35 EST 2009
What would these types be used for? If your students are complaining
about having to perform logarithms to store integers, inform them of
the "Integer" type.
The existing sized types -- Word/Int [8, 16, 32, 64] -- are useful
primarily because they match up with "standard" integral data types in
other languages. They're great for FFI, (un)marshaling via ByteString,
and occasional low-level code.
In contrast, there is (to my knowledge) no machine with 42-bit
integers, so there's no point to defining such intermediate types.
In your FileSize example, it would be much easier to simply use:
newtype FileSize = FileSize Integer
since then your code will cope nicely when everybody upgrades to PB
disks in a few years. If you need particular bounds, create your own
instance of Bounded.
More information about the Haskell-Cafe