[Haskell-beginners] A Quantity Type - Integer without the Negative #'s

Magnus Therning magnus at therning.org
Fri May 8 18:06:37 EDT 2009


aditya siram wrote:
> Hi all,
> Is there a datatype in Haskell that can be used to represent only 
> quantities >= 0?  I got bitten by a bug because I forgot to reject an 
> amount that was below zero after applying a decrementing operator. A 
> simple unit test would have caught this, but I was wondering if there 
> was some way of getting the type system to ensure this.

Maybe Word32 (or one of it's siblings) would do?  It's basically the 
same as 'unsigned int' in C, so it can under- and over-flow.

/M

-- 
Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
Url : http://www.haskell.org/pipermail/beginners/attachments/20090508/c11af4db/signature.bin


More information about the Beginners mailing list