The Thaumatorium:
Where the magic happens

The different types of functions in Functional Programming

Slightly annoying that 'type' already have a certain meaning in Haskell, but I think you're smart enough to understand what I mean with the title.

In this context, a parser is a function accepting strings as input and returning some data structure as output, typically it's a parse tree or a set of indices representing locations in the string where parsing stopped successfully.

Type What it does Example code
Pure Takes an input, returns an output – no side effects (data changes)
f :: Int -> Int
f x = x
Predicate Takes an input, returns a Bool
f :: Int -> Bool
f x = x > 5
Recursive Like a Pure function, but also calls itself (at least once) with a subset of the original input
length :: [a] -> Int
length (x:xs) = 1 + length xs
Curried You can give a function a part of the input to create a new function (imperative languages like C or Python always want all arguments at once)
timesTwo :: Int -> Int
timesTwo = 2 *
As you can see, the * operator only has one input – It's been partially applied! When you look at the definition, you see that timesTwo expects at least one Int, which when applied, gets added at the end of the function:
timesTwo 3
= { apply timesTwo }
2 * 3
= { apply * }
6
Applicative Can take a variable amount of inputs, returns an output Uses a function (pure) and an operator (<*>), where 'pure' lifts the function into a wrapped type/function and '<*>' accepts a wrapped type/function and a variable (that's also wrapped)
Monadic Takes an input, returns an output – has side effects (data changes) and uses either the bind >>= operator or do notation From: https://wiki.haskell.org/All_About_Monads
maternalGrandfather :: Sheep -> Maybe Sheep
maternalGrandfather s = (return s) >>= mother >>= father
-- alternatively
mothersPaternalGrandfather :: Sheep -> Maybe Sheep
mothersPaternalGrandfather s = do m <- mother s
																	gf <- father m
																	father gf
Parser Combinator Accepts several parsers as input and returns a new parser as its output. From: https://en.wikipedia.org/wiki/Parser_combinator In this context, a parser is a function accepting strings as input and returning some structure as output, typically a parse tree or a set of indices representing locations in the string where parsing stopped successfully.