Real World Haskell - 第4章 Part9 Partial function application and currying

Real World HaskellHaskell を継続的に勉強中。


Chapter 4. Functional programming
Chapter 4. Functional programming

Partial function application and currying

この説明を待っていた!

You may wonder why the -> arrow is used for what seems to be two purposes in the type signature of a function.

4章も後半になって、RWH がだんだん楽しくなってきたぞ。

  • The implication here is very important: in Haskell, all functions take only one argument.
  • Partial function application / partial application / partially applied function
    • λ関数で書くよりも便利なときがある
    • Partial function application is named currying
isInAny2 needle haystack = any (\s -> needle `isInfixOf` s) haystack
isInAny3 needle haystack = any (isInfixOf needle) haystack
  • section を使って更にこう書ける
isInAny4 needle haystack = any (needle `isInfixOf`) haystack