Parameters and patterns

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 -- DECOM - ICEB - UFOP

I think every people will have different terms.
For instance, for my teachers, argument and parameter were synonyms, and :
in the definition :
f x = x + 3
x was a _formal_ parameter (or argument)
and in
f 32
32 was the _effective_ parameter.
So, short answer: don't bother.
Context makes things clear enough.
2011/10/1 José Romildo Malaquias
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 -- DECOM - ICEB - UFOP
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hello, 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.
g (_:xs) = xs (_:xs) is something similar as a name. You might say '(_:xs)' stands for the
g y@(_:xs) = xs you might probably say "y is the parameter of g" - but y is just a name for
If you look at 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 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
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 -- DECOM - ICEB - UFOP
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 10/1/11 10:27 AM, José Romildo Malaquias wrote:
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?
As Yves says, I think it's probably best not to worry about it. Different people use different terminology. And so long as you understand the difference between the actual values passed to functions and the way functions refer to those values, then you're fine. As for this example, it might be helpful to consider the fact that the given definition is syntactic sugar for what's actually being executed. (Or maybe it'll only muddle issues further.) Namely, definitions of the form f x y ... z = e are syntactic sugar for f = \x y ... z -> e which makes explicit that f is just a name for referring to some lambda abstraction. And definitions which use pattern matching f p = e are just sugar for case analysis f x = case x of p -> e (where x does not appear in p or e.) So your definition is equal to g = \x -> case x of (_:xs) -> xs -- Live well, ~wren

On 2/10/2011, at 3:27 AM, José Romildo Malaquias wrote:
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.
Who told you that? Variables are one thing and names are another. I think you are talking about what the definition of Algol 60 called a "formal parameter". It's worth noting that formal parameters in Algol 60 could be labels, switches, and procedures, while there were no label variables, switch variables, or procedure variables. Names and variables are *really* different things. For what it's worth, the Haskell 2010 report appears to use "parameter" informally to mean - a formal parameter of a function - a formal parameter position of a type constructor - a constant characterising a numeric type but I don't see a precise definition anywhere.
Argument is the value to which the function is applied.
I think you are talking about what the definition of Algol 60 called an "actual parameter". The word "argument" is very often used for formal parameters too. For what it's worth, the Haskell 2010 report appears to use "argument" informally to mean - an actual parameter of a function - an actual parameter of a type constructor but I don't see a precise definition anywhere.
Now I am not sure how to apply these concepts to Haskell, as Haskell uses pattern matching to deal with argument passing to functions.
Realise that what you thought you knew was a half truth: all formal parameters are patterns, and all (new) identifiers are patterns, but not all patterns are identifiers. (And of course that is a half truth too.)
For instance, in the definition
f x = 2 * x + 1
x is a parameter, and in the application
a parameter, or an argument, or a formal parameter, or a formal argument, or what you please.
f 34
34 is an argument
an argument, or a parameter, or an actual parameter, or an actual argument, or what you please.
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.
Why? Patterns are a generalisation of variables. Practically all functional languages since lisp use pattern matching, and even Lisp these days has destructuring-bind.
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?
This is the point where some people would say "this is just semantics". The problem is that it is precisely NOT semantics. You clearly understand the *semantics* here; what's bothering you is the lexical level, what to call something. The first occurrence of xs is "a binding occurrence of an identifier inside a formal parameter" and the second occurrence is "an applied occurence of an identifier". The Haskell 2010 report often uses "parameter" to refer to a formal parameter _place_ of a function rather than to the text that fills that place in a function definition. On that reading, (_:xs) is *not* a parameter, it's a pattern that appears in the first parameter *position* of g, and parameters as such do not have names.
I am writing some slides to use in my functional programming classes, but I am not sure how to deal with these terms.
Consistently with the text-book.
participants (5)
-
José Romildo Malaquias
-
Richard O'Keefe
-
Wolfgang Braun
-
wren ng thornton
-
Yves Parès