HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulelinear-base-0.4.0Haskell2010

Data.Functor.Linear.Internal.Applicative

  • 1 class
  • 2 values
classclass Functor f => Applicative (f :: Type -> Type) where
#

Data Applicative-s can be seen as containers which can be zipped together. A prime example of data Applicative are vectors of known length (ZipLists would be, if it were not for the fact that zipping them together drops values, which we are not allowed to do in a linear container).

In fact, an applicative functor is precisely a functor equipped with (pure and) liftA2 :: (a %1-> b %1-> c) -> f a %1-> f b %1-> f c. In the case where f = [], the signature of liftA2 would specialise to that of zipWith.

Intuitively, the type of liftA2 means that Applicatives can be seen as containers whose "number" of elements is known at compile-time. This includes vectors of known length but excludes Maybe, since this may contain either zero or one value. Similarly, ((->) r) forms a Data Applicative, since this is a (possibly infinitary) container indexed by r, while lists do not, since they may contain any number of elements.

Remarks for the mathematically inclined

An Applicative is, as in the restricted case, a lax monoidal endofunctor of the category of linear types. That is, it is equipped with

  • a (linear) function () %1-> f ()

  • a (linear) natural transformation (f a, f b) %1-> f (a, b)

It is a simple exercise to verify that these are equivalent to the definition of Applicative. Hence that the choice of linearity of the various arrow is indeed natural.

Methods

  • pure :: a -> f a
  • (<*>) :: f (a %1 -> b) %1 -> f a %1 -> f binfixl 4
  • liftA2 :: (a %1 -> b %1 -> c) -> f a %1 -> f b %1 -> f c
Instances23Applicative, …
valuegenericLiftA2
  1. :: (Generic1 f, GApplicative ('ShowType f) (Rep1 f))
  2. => a %1 -> b %1 -> c
  3. -> f a
  4. -> f b
  5. -> f c
#

Orphan instances

2 instances