Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
applicative [2014/08/24 00:53] nikolaj |
applicative [2014/08/25 00:06] nikolaj |
||
---|---|---|---|
Line 1: | Line 1: | ||
===== Applicative ===== | ===== Applicative ===== | ||
==== Haskell class ==== | ==== Haskell class ==== | ||
+ | === Definition === | ||
<code/Haskell> | <code/Haskell> | ||
+ | -- definition | ||
class Functor f => Applicative f where | class Functor f => Applicative f where | ||
pure :: a -> f a | pure :: a -> f a | ||
(<*>) :: f (a -> b) -> f a -> f b | (<*>) :: f (a -> b) -> f a -> f b | ||
</code> | </code> | ||
+ | |||
+ | | pure id <*> v $\ \leftrightsquigarrow\ $ v | | ||
+ | | pure f <*> pure x $\ \leftrightsquigarrow\ $ pure (f x) | | ||
+ | | u <*> pure y $\ \leftrightsquigarrow\ $ pure ($ y) <*> u | | ||
+ | | u <*> (v <*> w) $\ \leftrightsquigarrow\ $ pure (.) <*> u <*> v <*> w | | ||
==== Discussion ==== | ==== Discussion ==== | ||
Applicative is a functor together with a polymorphic function 'pure' lifting terms, as well as a function '(<*>)' which applies terms in the lifted function type to lifted terms. Note that 'f (a -> b)' is generally not a function space. E.g. the term 'Nothing' of 'Maybe (a->b)' isn't a function. | Applicative is a functor together with a polymorphic function 'pure' lifting terms, as well as a function '(<*>)' which applies terms in the lifted function type to lifted terms. Note that 'f (a -> b)' is generally not a function space. E.g. the term 'Nothing' of 'Maybe (a->b)' isn't a function. | ||
- | |||
- | === Postulates === | ||
- | ^ pure id <*> v $\ \leftrightsquigarrow\ $ v ^ | ||
- | ^ pure f <*> pure x $\ \leftrightsquigarrow\ $ pure (f x) ^ | ||
- | ^ u <*> pure y $\ \leftrightsquigarrow\ $ pure ($ y) <*> u ^ | ||
- | ^ u <*> (v <*> w) $\ \leftrightsquigarrow\ $ pure (.) <*> u <*> v <*> w ^ | ||
- | |||
- | === Associated methods === | ||
- | >todo | ||
=== Reference === | === Reference === |