1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
module Control.Applicative
( Applicative(..), liftA, liftA3, when
, sequenceA, sequenceA_
) where
liftA :: Applicative f => (a -> b) -> f a -> f b
liftA f a = pure f <*> a
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
liftA3 f a b c = liftA2 f a b <*> c
when :: (Applicative f) => Bool -> f () -> f ()
when p s = if p then s else pure ()
sequenceA :: (Applicative f) => [f a] -> f [a]
sequenceA [] = pure []
sequenceA (x:xs) = (:) <$> x <*> sequenceA xs
sequenceA_ :: (Applicative f) => [f a] -> f ()
sequenceA_ = foldr (*>) (pure ())
|