[Haskell-cafe] Data constructor synonyms

Roel van Dijk vandijk.roel at gmail.com
Fri Mar 18 12:22:23 CET 2011


Remember that constructors are functions, except that you can't
pattern match against them.

> data MyType = GeneralConstructor [Double]

> -- GeneralConstructor :: [Double] -> MyType

Note the lower case character, just a plain function:
> specialConstructor :: Double -> MyType
> specialConstructor a = GeneralConstructor (a:[])

> zero :: MyType
> zero = GeneralConstructor [0]

The downside is that you can't pattern-match against these functions.



More information about the Haskell-Cafe mailing list