Hey there,
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 =
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?
1. this only works with dependent types, which Haskell does not have -
by design (type inference/checking would be undecidable).
It works
type Point = (Int, Int)
2. using type (instead of data) is generally a bad idea.
and in this case, using data Point ... would allow to
define a smart constructor that can at least check at run-time
whether the bounds are met. - J.W.
signature.asc
Description: OpenPGP digital signature
On Mon, Sep 01, 2008 at 11:45:12AM +0200, Brettschneider, Matthias wrote:
Hey there,
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