[Haskell-beginners] function application

Silent Leaf silent.leaf0 at gmail.com
Sun Apr 10 21:29:27 UTC 2016


Mike: If you seek as I think you do, to write the function mc (partially)
in point-free style, you must know this style implies no arguments, or at
least not all arguments, mentioned, that is for example here:
mc x | x < 100 = x - 10
mc = mc . mc . (+ 11)

The second line will only be checked for pattern matching if the first one
fails, so it amounts to the "otherwise" guard as here there's no pattern,
so it's a bit like the pattern that always matches (mc _ = ...)
You'll remark I did write (mc =) and not (mc x =). Point free style amounts
to describing a function through a composition of other functions, in an
arguments-free way, here for example, (mc . mc . (+11)) being the
composition of mc twice, with the "partially-applied" function (+11) == (\x
-> x + 11) == (11+). This partially applied notation works for all
operators by the way.

And for the record, the whitespace operator is a pure myth. First you can
remove all whitespace, it still works. Second, try using the same
whitespace-induced universal right-associativity with (f a b): does it
amount to (f (a b))?

The reason for this right-associativity interpretation in (mc . mc (x +
11)) is because (.) itself is right associative: right-directed greediness
could we say, in the vocabulary of regular expression. It's also the case
of ($), and that's why we use it to counter the natural left associativity
of function application:
f $ g a == f $ (g a) == ($) f (g a) == f (g a)   -- (using the definition
of ($) here)
instead of
f g a == (f g) a
without using ($).

The whitespace is just a meaningless character (I guess, a set of
characters) used to separate juxtaposed meaningful tokens of the language
when we have either (symbol,symbol) or (nonsymbol,nonsymbol), for example
respectively (!! $ /= !!$) and (f g /= fg). whenever it's a nonsymbol and a
symbol, whitespace is not necessary (a+, +a).
Then there's the automatic, implicit function application between two
juxtaposed non-symbolic tokens. But the whitespace has never been an
operator of any kind, and is totally meaningless (and optional) in (mc . mc
(x + 11)).

Especially too, it's clear no whitespace survives the tokenization during
the lexical phase of the (pre?) compilation, contrarily to all real
operators like (+).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160410/75497f7a/attachment-0001.html>


More information about the Beginners mailing list