On Nov 16, 2007 12:26 AM, Lennart Augustsson <[EMAIL PROTECTED]> wrote:
> On Nov 14, 2007 1:05 AM, Robin Green <[EMAIL PROTECTED]> wrote:
> >
> > On Tue, 13 Nov 2007 13:51:13 -0800
> > "Dan Piponi" <[EMAIL PROTECTED]> wrote:
> >
> > > Up until yesterday I had presumed that guards only applied to
> > > functions. But I was poking about in the Random module and discovered
> > > that you can write things like
> > >
> > > a | x > 1 = 1
> > >   | x < -1 = -1
> > >   | otherwise = x
> > >
> > > where 'a' clearly isn't a function.
> >
> > Isn't it a function taking zero arguments?
>
> No, Haskell functions take exactly one argument.

Depends on who you ask. From [1]:

<quote>
taxRate = 0.06

total cart = subtotal + tax
  where
    subtotal = sum cart
    taxable  = filter isTaxable cart
    tax = (sum taxable) * taxRate

This example defines two functions, taxRate, which returns a constant
value, and total, which computes the total cost of the list of items
in a shopping cart. (Although the taxRate definition appears to be
defining a variable, it's best to think of it as a constant function,
a function that takes no parameters and always returns the same
value.) The definition of total is quite expressive, and highlights
the intent of the function, by isolating and naming important
sub-expressions in the computation. (total also refers to an isTaxable
function, not presented here.)
</quote>

Technically, all Haskell functions may take exactly one parameter -
but focusing only on semantics, I guess there's really nothing wrong
with considering constants as parameterless functions, is there?

[1]

cheers,
Arnar
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to