Functional programming terms in my own words
This article is a reference (mostly for myself) that gives simple explanations for functional programming terms. It also shows relations between terms.
Much of the information here has been learned from the excellent book, PureScript by Example.
A type class that supports concatenation.
The concatentation operatior is
class Semigroup a where (<>) :: a -> a -> a
[1,2] <> [3,4] = [1,2,3,4]
"hi " <> "everyone" = "hi everyone"
A type class that has an empty value.
class (Semigroup m) <= Monoid m where mempty :: m
A Monoid is also a:
[1,2] <>  = [1,2]
"" <> "hey"= "hey"
A type class. Still working on the mental model for this one.
Here are the laws:
class Foldable f where foldr :: forall a b. (a -> b -> b) -> b -> f a -> b foldl :: forall a b. (b -> a -> b) -> b -> f a -> b foldMap :: forall a m. (Monoid m) => (a -> m) -> f a -> m
A type class that uses the lifting operator (think map).
class Functor f where (<$>) :: forall a b. (a -> b) -> f a -> f b
It also follows the following laws:
- Identity law:
id <$> x = x
- Composition law:
g <$> (f <$> x) = (g <<< f) <$> x
Defines pure and <*>
An applicative is a: