[Haskell-cafe] Parameters and patterns

Wolfgang Braun t3eblinder at googlemail.com
Sat Oct 1 18:36:17 CEST 2011


I think you have to remember that is x in
> f x = 2 * x + 1
is just a name for the parameter and not the parameter itself.

If you look at
> g (_:xs) = xs
(_:xs) is something similar as a name. You might say '(_:xs)' stands for the
parameter (you can't say it is the name of the parameter...).  And xs is
just the name of the part of the parameter.

In the case of
> g y@(_:xs) = xs
you might probably say "y is the parameter of g" - but y is just a name for
that parameter.

There is a difference between names, entities and bindings. Can be confusing
if you take a look at this quote:

“The name of the song is called ‘Haddocks’ Eyes’.”
>     “Oh, that’s the name of the song, is it?” Alice said, trying to feel
> interested.
>     “No, you don’t understand,” the Knight said, looking a little vexed.
> “That’s what the name is called.
> The name really is ‘The Aged Aged Man’.”
>     “Then I ought to have said ‘That’s what the song is called’?” Alice
> corrected herself.
>     “No, you oughtn’t: that’s quite another thing! The song is called ‘Ways
> and Means’; but that’s only
> what it’s called, you know!”
>     “Well, what is the song, then?” said Alice, who was by this time
> completely bewildered.
>     “I was coming to that,” the Knight said. “The song really is ‘A-sitting
> On A Gate’; and the tune’s
> my own invention.”
> L. Caroll, Through the Looking Glass

2011/10/1 José Romildo Malaquias <j.romildo at gmail.com>

> Hello.
> When studing programming languages I have learned that parameter is a
> variable (name) that appears in a function definition and denotes the
> value to which the function is applied when the function is called.
> Argument is the value to which the function is applied.
> The parameter allows the manipulation of the argument in the body of the
> funtion definition in order to produce the result.
> Now I am not sure how to apply these concepts to Haskell, as Haskell
> uses pattern matching to deal with argument passing to functions.
> For instance, in the definition
>  f x = 2 * x + 1
> x is a parameter, and in the application
>  f 34
> 34 is an argument.
> But in the definition
>  g (_:xs) = xs
> what is the parameter of the function g? Is it the pattern (_:xs)? If so
> then a parameter is not necessarily a variable anymore, and that seems
> very strange. And what is xs? Is it a parameter, although it does not
> denote the value to which the function is aplied, but just part of it?
> I am writing some slides to use in my functional programming classes,
> but I am not sure how to deal with these terms.
> Any comments?
> Romildo
> --
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111001/dfbce32a/attachment.htm>

More information about the Haskell-Cafe mailing list