notes

Personal notes
git clone git://git.laack.co/notes.git
Log | Files | Refs

Currying.md (851B)


      1 # Currying (Haskell)
      2 
      3 **Source:** Effective Haskell
      4 
      5 **Chapter:** 1
      6 
      7 **Definition:** Currying is the process of converting a function that takes multiple inputs into a function that takes one input and returns a new function with the remainder of the inputs that returns the result.
      8 
      9 ```haskell
     10 
     11 makeThruple a b c = (a,b,c)
     12 makeThruple' a b = \c -> (a,b,c)
     13 makeThruple''= \a -> \b -> \c -> (a,b,c)
     14 
     15 ```
     16 
     17 In the above example, we see we are able to decrease the number of inputs to a given function by defining an anonymous function that takes as input the remaining parameters and returns the result.
     18 
     19 NOTE: The backslash character in Haskell is used to define anonymous (lambda) functions.
     20 
     21 In Haskell, you can't define functions with multiple inputs, instead the language under the hood is performing currying, as illustrated in the above example.