G'day all.

Quoting Neil Mitchell <[EMAIL PROTECTED]>:

It's nice to write functions in point free style:

f = sort . nub

But sometimes I have to add an extra case, on a certain value:

f [] = [1]
f = sort . nub

But now these equations have different arities, and its rejected by
Haskell.

I don't know why Haskell does it specifically, but here's why I like
the behaviour:

1. Equations with different arities more often signal bugs than
correct intentions.  One common situation is adding an argument to
a function, and accidentally leaving one equation out.

2. It's highly misleading.

This:

    f [] = [1]
    f = sort . nub

suggests that f is (sort . nub), which is most decidedly is not.

By forcing you to add the argument:

    f [] = [1]
    f xs = sort . num $ xs

it reminds you more strongly that what you're actually writing is a
shorthand for this:

    f [] = [1]
    f xs@(_:_) = sort . num $ xs

Cheers,
Andrew Bromage
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to