[Haskell-cafe] Re: Renaming constructors for readability
apfelmus at quantentunnel.de
Wed Nov 14 03:59:05 EST 2007
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
More information about the Haskell-Cafe