ap package:rebase

In many situations, the liftM operations can be replaced by uses of ap, which promotes function application.
return f `ap` x1 `ap` ... `ap` xn
is equivalent to
liftMn f x1 x2 ... xn
This data type witnesses the lifting of a Monoid into an Applicative pointwise.
Recover the application operator <*> from select. Rigid selective functors satisfy the law <*> = apS and furthermore, the resulting applicative functor satisfies all laws of Applicative:
  • Identity:
    pure id <*> v = v
  • Homomorphism:
    pure f <*> pure x = pure (f x)
  • Interchange:
    u <*> pure y = pure ($y) <*>
    u
  • Composition:
    (.) <$> u <*> v <*> w = u
    <*> (v <*> w)
The computation appendFile file str function appends the string str, to the file file. Note that writeFile and appendFile write a literal string to a file. To write a value of any printable type, as with print, use the show function to convert the value to a string first.
main = appendFile "squares" (show [(x,x*x) | x <- [0,0.1..2]])
applyWhen applies a function to a value if a condition is true, otherwise, it returns the value unchanged. It is equivalent to flip (bool id). Algebraic properties:
approxRational, applied to two real fractional numbers x and epsilon, returns the simplest rational number within epsilon of x. A rational number y is said to be simpler than another y' if Any real interval contains a unique simplest rational; in particular, note that 0/1 is the simplest rational of all.
A functor with application, providing operations to
  • embed pure expressions (pure), and
  • sequence computations and combine their results (<*> and liftA2).
A minimal complete definition must include implementations of pure and of either <*> or liftA2. If it defines both, then they must behave the same as their default definitions:
(<*>) = liftA2 id
liftA2 f x y = f <$> x <*> y
Further, any definition must satisfy the following: The other methods have the following default definitions, which may be overridden with equivalent specialized implementations: As a consequence of these laws, the Functor instance for f will satisfy It may be useful to note that supposing
forall x y. p (q x y) = f x . g y
it follows from the above that
liftA2 p (liftA2 q u v) = liftA2 f u . liftA2 g v
If f is also a Monad, it should satisfy (which implies that pure and <*> satisfy the applicative functor laws).
A strong lax semi-monoidal endofunctor. This is equivalent to an Applicative without pure. Laws:
(.) <$> u <.> v <.> w = u <.> (v <.> w)
x <.> (f <$> y) = (. f) <$> x <.> y
f <$> (x <.> y) = (f .) <$> x <.> y
The laws imply that .> and <. really ignore their left and right results, respectively, and really return their right and left results, respectively. Specifically,
(mf <$> m) .> (nf <$> n) = nf <$> (m .> n)
(mf <$> m) <. (nf <$> n) = mf <$> (m <. n)
A more meaningful and conflict-free alias for first.
A more meaningful and conflict-free alias for second.
Some arrows allow application of arrow inputs to other inputs. Instances should satisfy the following laws: Such arrows are equivalent to monads (see ArrowMonad).