Comment

Comment by hackyhacky

I understand the author's position, and despite its usefulness, I think the numbered arguments are an inelegant solution. In Haskell, by way of comparison, any one-parameter function can be used as the argument to map:

  ghci> map reverse ["hello", "goodbye"]
  ["olleh","eybdoog"]
is (mostly) equivalent to the more verbose form with an explicit lambda:

  ghci> map (\s -> reverse s) ["hello", "goodbye"]
  ["olleh","eybdoog"]
Operators are just normal functions, but tuples are not automatically uncurried. Here I'm using the multiply operator (*) to multiple a list of pairs:

  ghci> map (*) [(1,2), (3,4)]
  ERROR
  ghci> map (uncurry (*)) [(1,2), (3,4)]
  [2,12]
Points-free syntax can be used to construct chains of operations without any explicit lambda variable. Here filter strings of more than two characters:

  ghci> filter ((>2) . length) ["a","bb","ccc","dddd"]
  ["ccc","dddd"]
In lambda syntax:

  ghci> filter (\x -> (length x) > 2) ["a","bb","ccc","dddd"]
  ["ccc","dddd"]
I find the Haskell syntax concise and clear, and I always miss it when using other languages (despite Haskell's other shortcomings).

Edit: formatting

parent hackyhacky 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton