[Haskell-cafe] All equations must have the same arity - why?

ajb at spamcop.net ajb at spamcop.net
Mon Jan 14 01:42:57 EST 2008

G'day all.

Quoting Neil Mitchell <ndmitchell at gmail.com>:

> I don't believe that. I suspect the type system will mop these up.

As previously noted, anything involving undefined (thanks to seq) is
not equivalent.

While undefined is arguably uncommon, error most certainly isn't:

     f1 (x:xs) = {- something -}
     f1 [] = error "empty list"

     -- add an argument, to get...
     f2 (x:xs) y = {- something -}
     f2 [] = error "empty list"

f2 is type-correct, but is subtly different from f1, both semantically
and (I think) performance-wise.

On sharing: It's not generally appreciated, but in GHC, there's a subtle
difference between:

     g x y = let z = p x in q x y z


     g x = \y -> let z = p x in q x y z

the difference being that in the latter, the definition of z can be

     g x = let z = p x in \y -> q x y z

GHC does not float lets over lambdas if it would "break" a group of
function arguments.  Any proposed desugaring would have to either come
up with a better rule than this, or find a way to preserve it.

Andrew Bromage

More information about the Haskell-Cafe mailing list