· functional programming purescript haskell tips

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.

Terms

Type Class

A thing.

Semigroup

A type class that supports concatenation.

The concatentation operatior is <>

class Semigroup a where
  (<>) :: a -> a -> a

Examples

Monoid

A type class that has an empty value.

class (Semigroup m) <= Monoid m where
  mempty :: m

A Monoid is also a:

Examples

Foldable

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

Functor

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:

Applicative

Defines pure and <*>

An applicative is a:

← JSON requests and the 2nd Evil Ex Migrate your domain email from Zoho to FastMail →