[Haskell-cafe] Parameters and patterns

wren ng thornton wren at freegeek.org
Sun Oct 2 02:59:55 CEST 2011


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



More information about the Haskell-Cafe mailing list