Haskell Language Applicative Functor Alternative definition

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 Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Since every Applicative Functor is a Functor, fmap can always be used on it; thus the essence of Applicative is the pairing of carried contents, as well as the ability to create it:

class Functor f => PairingFunctor f where
  funit :: f ()                  -- create a context, carrying nothing of import
  fpair :: (f a,f b) -> f (a,b)  -- collapse a pair of contexts into a pair-carrying context

This class is isomorphic to Applicative.

pure a = const a <$> funit = a <$ funit  

fa <*> fb = (\(a,b) -> a b) <$> fpair (fa, fb) = uncurry ($) <$> fpair (fa, fb)

Conversely,

funit = pure ()

fpair (fa, fb) = (,) <$> fa <*> fb


Got any Haskell Language Question?