Hacker News new | ask | show | jobs
by Kiro 3667 days ago
Thanks! Is this the case in Elm as well? This is the example they give:

  connectWords : String -> String -> String
  connectWords firstWord secondWord =
    firstWord ++ secondWord
2 comments

In this case, you think of `connectWords` as a function that takes two arguments. But since it is curried, you can also do this:

    let prefix = connectWords "Hello "
        world  = prefix "world"
        bob    = prefix "bob"
    in ...
`world` is "Hello world", and `bob` is "Hello bob". That is the power of currying. A maybe more useful example is specifying the mapping function in `List.map` without supplying the list to map over. This allows you to use the same map with multiple lists.
Yes, all functions in Elm also have arity 1. That example desugars into this:

    connectWords = \ firstWord -> \ secondWord -> firstWord ++ secondWord