[Haskell-beginners] A Quantity Type - Integer without the
Negative #'s
Chaddaï Fouché
chaddai.fouche at gmail.com
Mon May 11 23:55:24 EDT 2009
2009/5/9 aditya siram <aditya.siram at gmail.com>:
> 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.
>
> -deech
>
>
> [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.
> [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
> where nothing is being constructed.
I don't see where the "predicated datatype" differs from the tags type
: Int could as well be implemented as a "data Int = 0 | 1 | 2 |..."
(sparing consideration about characters authorized in a tag), String
isn't primitive at all, in fact it's just a list of characters.... You
can easily create them. To specialize on a subset of them is very easy
too, you can use newtype or data and create a smart constructor, as
well as appropriate instances. The only problem is that it is pretty
hard to get compile time guarantee on some of them but no other
classic language provides more guarantee : the only languages that can
do better are those that have dependant types (Agda, Coq, Epigram...)
and as you'll know if you tried them they're frequently harder to use
than Haskell.
NB : You can use Template Haskell to get some compile-time errors for
the constants of your code.
--
Jedaï
More information about the Beginners
mailing list