Explanation for function composition and infix function application(PureScript) -
this code works
findname :: string -> string -> addressbook -> boolean findname fname lname = not <<< null <<< filter findn findn :: entry -> boolean findn entry = entry.firstname == fname && entry.lastname == lname
but not
findname fname lname book = not <<< null <<< filter findn book
again code works
findname fname lname book= not $ null $ filter findn book
and not
findname fname lname = not null $ filter findn
in short, because these different examples equivalent different placements of parentheses, code evaluated differently. f <<< g
, f
, g
functions, equivalent \x -> f (g x)
, whereas f x $ g y
equivalent (f x) (g y)
. whenever have infix symbol <<<
, no other infix symbols, expressions left , right of symbol evaluated first, first example evaluated
findname fname lname = ((not) <<< (null) <<< (filter findn))
,
which book
parameter made explicit
findname fname lname book = ((not) <<< (null) <<< (filter findn)) book
,
whereas second example evaluated
findname fname lname book = (not) <<< (null) <<< (filter findn book)
.
filter findn book
yields list, <<<
requires function arguments. third , fourth example problem similar: if make book
parameter explicit in 4th example,
findname fname lname = (not $ null (filter findn)) book
, (where forgot 1 $
).
not $ null $ ...
requires ...
addressbook
, filter findn
function, not addressbook.
Comments
Post a Comment