Dougal Stanton wrote:
I wonder, is there an equivalent of the 'type' keyword for
constructors? An example:
-- create a pseudo-C pointer type
-- which can point to a value or a
-- null.
type Pointer a = Maybe a
-- int a = 3;
-- int *pa = &a;
ampersand :: t -> Pointer t
ampersand a = Just a
-- int b = *pa.
star :: Pointer a -> a
star (Just a) = a
-- note this function behaves
-- in an 'authentic' fashion ;-)
To really complete the illusion it would be nice to replace the names
Just and Nothing with PointerTo and Null. Then the constructors would
really mean something. Is there a solution?
The thing you want is called "views". See
http://hackage.haskell.org/trac/ghc/wiki/ViewPatterns#Relatedwork
for more.
Regards,
apfelmus
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe