Haskell Language Category Theory Haskell Applicative in terms of Category Theory

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

A Haskell's Functor allows one to map any type a (an object of Hask) to a type F a and also map a function a -> b (a morphism of Hask) to a function with type F a -> F b. This corresponds to a Category Theory definition in a sense that functor preserves basic category structure.

A monoidal category is a category that has some additional structure:

Taking a pair as our product, this definition can be translated to Haskell in the following way:

class Functor f => Monoidal f where
    mcat :: f a -> f b -> f (a,b)
    munit :: f ()

The Applicative class is equivalent to this Monoidal one and thus can be implemented in terms of it:

instance Monoidal f => Applicative f where
    pure x = fmap (const x) munit
    f <*> fa = (\(f, a) -> f a) <$> (mcat f fa)


Got any Haskell Language Question?