Question: I'm having trouble understanding curried and uncurried functions. All the sites I Google'd to try to provide me a definition were unclear to me.

In one example I found them saying that

`max 4 5` is the same as `(max 4) 5`

But I don't understand what they're doing. How can you have a function `(max 4)` when max requires 2 parameters? I'm completely lost.

Answer: 
The trick with Haskell is that functions only take one argument. This seems totally crazy but it actually works.

A haskell function:

```
foo :: Int -> Int -> Int
foo a b = a + b

```

Really means: A function which takes in 1 argument, and then **returns another function which takes one argument**. This is called currying.

So using this, we can really write this function definition like this:

```
foo :: Int -> (Int -> Int) --In math speak: right associative

```

and mean exactly the same thing.

This is actually super useful because we can now write concise code like:

```
foo1 :: Int -> Int
foo1 = foo 1

```

Since function application in haskell is just whitespace, most of the time you can just pretend that curried functions are uncurried (taking more than one argument and just returning a result).

If you really really realllly need uncurried functions: Use tuples.

```
uncFoo :: (Int, Int) -> Int
uncFoo (a, b) = a + b

```

**Edit**

OK so to understand whats going on with partial application consider `bar`

```
bar a b c = [a, b, c]

```

The thing is, the compiler will desugar what you just typed into lambdas like this

```
bar = \a ->
      \b ->
      \c ->
           [a, b, c]

```

This takes advantage of closures (each inner function can 'remember' the arguments to the previous ones.

so when we say `bar 1`, the compiler goes and looks at `bar` and sees the outermost lambda, and applies it giving

```
bar 1 = \b ->
        \c ->
             [1, b, c]

```

If we say `bar 1 2`

```
bar 1 2 = \c ->
                [1, 2, c]

```

If what I mean when I say "apply" is hazy, then it may help to know that I really mean [beta reduction](http://en.wikipedia.org/wiki/Lambda_calculus#.CE.B2-reduction) from lambda calculus.
You probably got your answer already, but just to reiterate:

If we have

```
add x y = x + y

```

then we can say the following:

```
add = \ x y -> x + y
add 3 = \ y -> 3 + y
add 3 5 = 3 + 5 = 8

```

You ask "how can `max 3` calculate anything?", and the answer is "it can't". It just gives you another *function*. This function can do something when you call it, but you don't "get an answer" as such until *all* the arguments have been supplied. Until then, you just get functions.

Most of the time, this is just a useful syntactic shortcut. For example, you can write

```
uppercase :: String -> String
uppercase = map toUpper

```

instead of having to say

```
uppercase xs = map toUpper xs

```

Notice that if `map` had its arguments the other way around, we wouldn't be able to do this (you can only curry away the *last* argument, not the \_first), so it can be important to think about which order you define your functions' arguments.

---

I say "most of the time" because this is more than syntax sugar. There are several places in the language where you can handle functions with different numbers of arguments *polymorphically* because of currying. Every function either returns an answer, or another function. If you think of it like a linked list (which either contains the next item of data or the end-of-list marker), you can see how this lets you recursively process functions.

So what the heck do I mean by that? Well, for example, QuickCheck can test functions with *any* number of arguments (provided there's a way to auto-generate test data for each argument). This is possible because function types are curried. Every function either returns another function, or a result. If you think about it like a linked list, you can imagine QuickCheck recursively iterating over the function until no more arguments are left.

The following code snippet may or may not explain the idea:

```
class Arbitrary a where
  autogenerate :: RandomGenerator -> a

instance Arbitrary Int
instance Arbitrary Char
...

class Testable t where
  test t :: RandomGenerator -> Bool

instance Testable Bool where
  test rnd b = b

instance (Arbitrary a, Testable t) => Testable (a -> t) where
  test rnd f = test $ f (autogenerate rnd)

```

If we have a function `foo :: Int -> Int -> Bool`, then this is `Testable`. Why? Well, `Bool` is testable, therefore so is `Int -> Bool`, and therefore so is `Int -> (Int -> Bool)`.

By contrast, each size of tuple is a different size, so you have to write separate functions (or instances) for each and every size of tuple. You can't recursively process tuples, because they don't have a recursive structure.