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

Achim Schneider barsoap at web.de
Sun Jan 13 20:49:58 EST 2008


Jonathan Cast <jonathanccast at fastmail.fm> wrote:

> On 13 Jan 2008, at 5:27 PM, Achim Schneider wrote:
> 
> > "Neil Mitchell" <ndmitchell at gmail.com> wrote:
> >
> >> Hi,
> >>
> >> 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. Why does this not simply desugar to:
> >>
> >> f [] = [1]
> >> f x = (sort . nub) x
> >>
> >> i.e. lift the arities to the longest argument list.
> >>
> >> Is there a reason this isn't done?
> >>
> > Answer #2:
> >
> > Because you can't write
> >
> > f x = case x of
> > 	[] -> [1]
> >         -> sort.nub
> 
> But why not? 
> 
Because arities aren't lifted to the longest argument list.

> Treating case as syntax sugar for a higher-order  
> function, so that all binding occurrences of lambdas in the
> unsugared code are associated with lambdas, is a good thing, and
> offers a natural way of desugaring the above, one case at a time.
> 
What about

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

?

You could also do things like

f - x = (foo x).bar

with it. No more rewriting of pointfree code because of added
arguments...

-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 



More information about the Haskell-Cafe mailing list