Tutorial by Examples

For a C-style function call, e.g. plus(a, b); // Parentheses surrounding only the arguments, comma separated Then the equivalent Haskell code will be (plus a b) -- Parentheses surrounding the function and the arguments, no commas In Haskell, parentheses are not explicitly required for functi...
In the previous example, we didn't end up needing the parentheses, because they did not affect the meaning of the statement. However, they are often necessary in more complex expression, like the one below. In C: plus(a, take(b, c)); In Haskell this becomes: (plus a (take b c)) -- or equivale...
In Haskell, functions can be partially applied; we can think of all functions as taking a single argument, and returning a modified function for which that argument is constant. To illustrate this, we can bracket functions as follows: (((plus) 1) 2) Here, the function (plus) is applied to 1 yiel...
As another example, we have the function map, which takes a function and a list of values, and applies the function to each value of the list: map :: (a -> b) -> [a] -> [b] Let's say we want to increment each value in a list. You may decide to define your own function, which adds one to...

Page 1 of 1