[Haskell-beginners] Restricting integers in a type?
tom.davie at gmail.com
Sun Dec 28 11:08:21 EST 2008
type Coordinate = (RInt,RInt)
data RInt = Zero | One | Two | Three | Four | Five | Six | Seven |
Eight | Nine | Ten | Eleven
You might also want to add an instance of Num so that you can define
them simply by typing the relevant number, but then you'll lose the
type system checking the bounds.
On 28 Dec 2008, at 10:07, Colin Paul Adams wrote:
> I want to declare a type thus:
> type Coordinate = (Int, Int)
> But the two integers must be confined to the inclusive range 0-11. Can
> i express that in the type system?
> Colin Adams
> Preston Lancashire
> Beginners mailing list
> Beginners at haskell.org
More information about the Beginners