Cool, that's really interesting! So is it accurate to say "predicated" datatypes [1] such as Int and String are provided by Haskell but you cannot create them or specialize on a subset of them? And there are really only two types of datatypes, tags [2] and the "predicated" types. Compound datatypes are just a combination of the two. <br>
<br>-deech<br><br><br>[1] By predicated I mean a datatype that would actually cause a compiler error ( not a runtime error ) if a method returned an out-of-bounds value.<br>[2] By tags I mean the data constructors, but I find it easier to think of them as tags because they can appear alone, eg. data Coins = Penny | Nickel | Dime | Quarter<br>
where nothing is being constructed. <br><br><div class="gmail_quote">On Fri, May 8, 2009 at 5:06 PM, Magnus Therning <span dir="ltr"><<a href="mailto:magnus@therning.org">magnus@therning.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">aditya siram wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br>
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.<br>
</blockquote>
<br></div>
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.<br>
<br>
/M<br><font color="#888888">
<br>
-- <br>
Magnus Therning (OpenPGP: 0xAB4DFBA4)<br>
magnus@therning.org Jabber: magnus@therning.org<br>
<a href="http://therning.org/magnus" target="_blank">http://therning.org/magnus</a> <a href="http://identi.ca" target="_blank">identi.ca</a>|twitter: magthe<br>
<br>
</font><br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br>