[Haskell-beginners] Restricting integers in a type?

Thomas Davie 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.

Bob

On 28 Dec 2008, at 10:07, Colin Paul Adams wrote:

> Hello,
>
> 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
> http://www.haskell.org/mailman/listinfo/beginners



More information about the Beginners mailing list