Types (or classes) of Haskell functions

edit: my new site is here: https://thaumatorium.com/

Slightly annoying that type and class 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 structure as output, typically a parse tree or a set of indices representing locations in the string where parsing stopped successfully.

Function typenameWhat it doesExample code
PureTakes an input, returns an output – no side effects (data changes)f :: Int -> Int
f x = x
PredicateTakes an input, returns a Boolf :: Int -> Bool
f x = x > 5
RecursiveLike a Pure function, but also calls itself (at least once) with a subset of the original inputlength :: [a] -> Int
length (x:xs) = 1 + length xs
CurriedYou 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
ApplicativeCan take a variable amount of inputs, returns an outputUses 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)
MonadicTakes an input, returns an output – has side effects (data changes) and uses either the bind >>= operator or do notationFrom: 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 CombinatorAccepts 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.

edit: my new site is here: https://thaumatorium.com/