[Haskell-cafe] Types in bounds
Brettschneider at hs-albsig.de
Mon Sep 1 05:45:12 EDT 2008
i was just thinking about types in Haskell and I asked myself,
Is there a mechanism, that allows me to define a new type out of an existing one with some restrictions?
So that the new type is a subset of the existing one.
Lets imagine I want a type for a point like:
type Point = (Int, Int)
But what, if I can predict that the X and Y values are in a range between 0 and 100?
If someone defines a new point like:
p :: Point
p = (200, 400)
that is totally fine with the type definition above, but not correct in my context.
Is it possible, to put this information into the type? So that the compiler is able to recognize my mistake?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe