[Haskell-cafe] Renaming constructors for readability

Jules Bean jules at jellybean.co.uk
Wed Nov 14 10:38:05 EST 2007

Henning Thielemann wrote:
> On Tue, 13 Nov 2007, Dougal Stanton wrote:
>> On 13/11/2007, Henning Thielemann <lemming at henning-thielemann.de> wrote:
>>> On Tue, 13 Nov 2007, Dougal Stanton wrote:
>>>> -- int a = 3;
>>>> -- int *pa = &a;
>>>> ampersand :: t -> Pointer t
>>>> ampersand a = Just a
>>> What's bad about using 'ampersand' function as replacement for the
>>> constructor 'Just'?
>> I also wanted to use it in pattern matching but have the advantage of
>> all the stuff already written for Maybe.
> No problem, write a function like 'maybe' to inspect the data.
> Instead of 'f m' with
> f :: Maybe T -> S
> f (Just x) = g x
> f Nothing  = h

Yes. It is a problem.

Do you write all your code using higher-order functions, never matching 
explicitly on constructors? I don't.

Matching explicitly on constructors is an elegant and easy-to-read way 
to write programs. It's annoying to have to choose between (a) nicely 
named constructors and (b) being able to re-use library functions 
defined for Maybe.


More information about the Haskell-Cafe mailing list