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)||
|Predicate||Takes an input, returns a Bool||
|Recursive||Like a Pure function, but also calls itself (at least once) with a subset of the original input||
|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)||
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:
|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
|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.|