File tree Expand file tree Collapse file tree 14 files changed +531
-472
lines changed
Expand file tree Collapse file tree 14 files changed +531
-472
lines changed Original file line number Diff line number Diff line change @@ -16,4 +16,23 @@ bower install purescript-control
1616
1717## Module documentation
1818
19- [ ` docs/MODULE.md ` ] ( docs/MODULE.md )
19+ ### Functor/Applicative
20+ - [ Control.Functor] ( docs/Control.Functor.md )
21+ - [ Control.Apply] ( docs/Control.Apply.md )
22+
23+ ### Monad
24+ - [ Control.Bind] ( docs/Control.Bind.md )
25+ - [ Control.Monad] ( docs/Control.Monad.md )
26+
27+ ### Alternative/MonadPlus
28+ - [ Control.Alt] ( docs/Control.Alt.md )
29+ - [ Control.Plus] ( docs/Control.Plus.md )
30+ - [ Control.Alternative] ( docs/Control.Alternative.md )
31+ - [ Control.MonadPlus] ( docs/Control.MonadPlus.md )
32+
33+ ### Comonads
34+ - [ Control.Extend] ( docs/Control.Extend.md )
35+ - [ Control.Comonad] ( docs/Control.Comonad.md )
36+
37+ ### Lazy
38+ - [ Control.Lazy] ( docs/Control.Lazy.md )
Original file line number Diff line number Diff line change 1+ # Module Documentation
2+
3+ ## Module Control.Alt
4+
5+
6+ This module defines the ` Alt ` type class.
7+
8+ #### ` Alt `
9+
10+ ``` purescript
11+ class (Functor f) <= Alt f where
12+ (<|>) :: forall a. f a -> f a -> f a
13+ ```
14+
15+ The ` Alt ` type class identifies an associative operation on a type
16+ constructor. It is similar to ` Semigroup ` , except that it applies to
17+ types of kind ` * -> * ` , like ` Array ` or ` List ` , rather than concrete types
18+ ` String ` or ` Number ` .
19+
20+ ` Alt ` instances are required to satisfy the following laws:
21+
22+ - Associativity: ` (x <|> y) <|> z == x <|> (y <|> z) `
23+ - Distributivity: ` f <$> (x <|> y) == (f <$> x) <|> (f <$> y) `
24+
25+ For example, the ` Array ` (` [] ` ) type is an instance of ` Alt ` , where
26+ ` (<|>) ` is defined to be concatenation.
27+
28+
29+
Original file line number Diff line number Diff line change 1+ # Module Documentation
2+
3+ ## Module Control.Alternative
4+
5+
6+ This module defines the ` Alternative ` type class and associated
7+ helper functions.
8+
9+ #### ` Alternative `
10+
11+ ``` purescript
12+ class (Applicative f, Plus f) <= Alternative f where
13+ ```
14+
15+ The ` Alternative ` type class has no members of its own; it just specifies
16+ that the type constructor has both ` Applicative ` and ` Plus ` instances.
17+
18+ Types which have ` Alternative ` instances should also satisfy the following
19+ laws:
20+
21+ - Distributivity: ` (f <|> g) <*> x == (f <*> x) <|> (g <*> x) `
22+ - Annihilation: ` empty <*> f = empty `
23+
24+ #### ` some `
25+
26+ ``` purescript
27+ some :: forall f a. (Alternative f, Lazy (f [a])) => f a -> f [a]
28+ ```
29+
30+ Attempt a computation multiple times, requiring at least one success.
31+
32+ The ` Lazy ` constraint is used to generate the result lazily, to ensure
33+ termination.
34+
35+ #### ` many `
36+
37+ ``` purescript
38+ many :: forall f a. (Alternative f, Lazy (f [a])) => f a -> f [a]
39+ ```
40+
41+ Attempt a computation multiple times, returning as many successful results
42+ as possible (possibly zero).
43+
44+ The ` Lazy ` constraint is used to generate the result lazily, to ensure
45+ termination.
46+
47+
48+
Original file line number Diff line number Diff line change 1+ # Module Documentation
2+
3+ ## Module Control.Apply
4+
5+
6+ This module defines helper functions for working with ` Apply ` instances.
7+
8+ #### ` (<*) `
9+
10+ ``` purescript
11+ (<*) :: forall a b f. (Apply f) => f a -> f b -> f a
12+ ```
13+
14+ Combine two effectful actions, keeping only the result of the first.
15+
16+ #### ` (*>) `
17+
18+ ``` purescript
19+ (*>) :: forall a b f. (Apply f) => f a -> f b -> f b
20+ ```
21+
22+ Combine two effectful actions, keeping only the result of the second.
23+
24+ #### ` lift2 `
25+
26+ ``` purescript
27+ lift2 :: forall a b c f. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
28+ ```
29+
30+ Lift a function of two arguments to a function which accepts and returns
31+ values wrapped with the type constructor ` f ` .
32+
33+ #### ` lift3 `
34+
35+ ``` purescript
36+ lift3 :: forall a b c d f. (Apply f) => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
37+ ```
38+
39+ Lift a function of three arguments to a function which accepts and returns
40+ values wrapped with the type constructor ` f ` .
41+
42+ #### ` lift4 `
43+
44+ ``` purescript
45+ lift4 :: forall a b c d e f. (Apply f) => (a -> b -> c -> d -> e) -> f a -> f b -> f c -> f d -> f e
46+ ```
47+
48+ Lift a function of four arguments to a function which accepts and returns
49+ values wrapped with the type constructor ` f ` .
50+
51+ #### ` lift5 `
52+
53+ ``` purescript
54+ lift5 :: forall a b c d e f g. (Apply f) => (a -> b -> c -> d -> e -> g) -> f a -> f b -> f c -> f d -> f e -> f g
55+ ```
56+
57+ Lift a function of five arguments to a function which accepts and returns
58+ values wrapped with the type constructor ` f ` .
59+
60+
61+
Original file line number Diff line number Diff line change 1+ # Module Documentation
2+
3+ ## Module Control.Bind
4+
5+
6+ This module defines helper functions for working with ` Bind ` instances.
7+
8+ #### ` (=<<) `
9+
10+ ``` purescript
11+ (=<<) :: forall a b m. (Bind m) => (a -> m b) -> m a -> m b
12+ ```
13+
14+ A version of ` (>>=) ` with its arguments flipped.
15+
16+ #### ` (>=>) `
17+
18+ ``` purescript
19+ (>=>) :: forall a b c m. (Bind m) => (a -> m b) -> (b -> m c) -> a -> m c
20+ ```
21+
22+ Forwards Kleisli composition.
23+
24+ For example:
25+
26+ ``` purescript
27+ import Data.Array (head, tail)
28+
29+ third = tail >=> tail >=> head
30+ ```
31+
32+ #### ` (<=<) `
33+
34+ ``` purescript
35+ (<=<) :: forall a b c m. (Bind m) => (b -> m c) -> (a -> m b) -> a -> m c
36+ ```
37+
38+ Backwards Kleisli composition.
39+
40+ #### ` join `
41+
42+ ``` purescript
43+ join :: forall a m. (Bind m) => m (m a) -> m a
44+ ```
45+
46+ Collapse two applications of a monadic type constructor into one.
47+
48+ #### ` ifM `
49+
50+ ``` purescript
51+ ifM :: forall a m. (Bind m) => m Boolean -> m a -> m a -> m a
52+ ```
53+
54+ Execute a monadic action if a condition holds.
55+
56+ For example:
57+
58+ ``` purescript
59+ main = ifM ((< 0.5) <$> random)
60+ (trace "Heads")
61+ (trace "Tails")
62+ ```
63+
64+
65+
Original file line number Diff line number Diff line change 1+ # Module Documentation
2+
3+ ## Module Control.Comonad
4+
5+
6+ This module defines the ` Comonad ` type class.
7+
8+ #### ` Comonad `
9+
10+ ``` purescript
11+ class (Extend w) <= Comonad w where
12+ extract :: forall a. w a -> a
13+ ```
14+
15+ ` Comonad ` extends the ` Extend ` class with the ` extract ` function
16+ which extracts a value, discarding the comonadic context.
17+
18+ ` Comonad ` is the dual of ` Monad ` , and ` extract ` is the dual of
19+ ` pure ` or ` return ` .
20+
21+ Laws:
22+
23+ - Left Identity: ` extract <<= xs = xs `
24+ - Right Identity: ` extract (f <<= xs) = f xs `
25+
26+
27+
Original file line number Diff line number Diff line change 1+ # Module Documentation
2+
3+ ## Module Control.Extend
4+
5+
6+ This module defines the ` Extend ` type class and associated helper functions.
7+
8+ #### ` Extend `
9+
10+ ``` purescript
11+ class (Functor w) <= Extend w where
12+ (<<=) :: forall b a. (w a -> b) -> w a -> w b
13+ ```
14+
15+ The ` Extend ` class defines the extension operator ` (<<=) `
16+ which extends a local context-dependent computation to
17+ a global computation.
18+
19+ ` Extend ` is the dual of ` Bind ` , and ` (<<=) ` is the dual of
20+ ` (>>=) ` .
21+
22+ Laws:
23+
24+ - Associativity: ` extend f <<< extend g = extend (f <<< extend g) `
25+
26+ #### ` extendArr `
27+
28+ ``` purescript
29+ instance extendArr :: (Semigroup w) => Extend (Prim.Function w)
30+ ```
31+
32+
33+ #### ` (=>>) `
34+
35+ ``` purescript
36+ (=>>) :: forall b a w. (Extend w) => w a -> (w a -> b) -> w b
37+ ```
38+
39+ A version of ` (<<=) ` with its arguments flipped.
40+
41+ #### ` (=>=) `
42+
43+ ``` purescript
44+ (=>=) :: forall b a w c. (Extend w) => (w a -> b) -> (w b -> c) -> w a -> c
45+ ```
46+
47+ Forwards co-Kleisli composition.
48+
49+ #### ` (=<=) `
50+
51+ ``` purescript
52+ (=<=) :: forall b a w c. (Extend w) => (w b -> c) -> (w a -> b) -> w a -> c
53+ ```
54+
55+ Backwards co-Kleisli composition.
56+
57+ #### ` extend `
58+
59+ ``` purescript
60+ extend :: forall b a w. (Extend w) => (w a -> b) -> w a -> w b
61+ ```
62+
63+ An alias for ` (<<=) ` .
64+
65+ #### ` duplicate `
66+
67+ ``` purescript
68+ duplicate :: forall a w. (Extend w) => w a -> w (w a)
69+ ```
70+
71+ Duplicate a comonadic context.
72+
73+ ` duplicate ` is dual to ` Control.Bind.join ` .
74+
75+
76+
Original file line number Diff line number Diff line change 1+ # Module Documentation
2+
3+ ## Module Control.Functor
4+
5+
6+ This module defines helper functions for working with ` Functor ` instances.
7+
8+ #### ` (<$) `
9+
10+ ``` purescript
11+ (<$) :: forall f a b. (Functor f) => a -> f b -> f a
12+ ```
13+
14+ Ignore the return value of a computation, using the specified return value instead.
15+
16+ #### ` ($>) `
17+
18+ ``` purescript
19+ ($>) :: forall f a b. (Functor f) => f a -> b -> f b
20+ ```
21+
22+ A version of ` (<$) ` with its arguments flipped.
23+
24+
25+
Original file line number Diff line number Diff line change 1+ # Module Documentation
2+
3+ ## Module Control.Lazy
4+
5+
6+ This module defines the ` Lazy ` type class and associated
7+ helper functions.
8+
9+ #### ` Lazy `
10+
11+ ``` purescript
12+ class Lazy l where
13+ defer :: (Unit -> l) -> l
14+ ```
15+
16+ The ` Lazy ` class represents types which allow evaluation of values
17+ to be _ deferred_ .
18+
19+ Usually, this means that a type contains a function arrow which can
20+ be used to delay evaluation.
21+
22+ #### ` fix `
23+
24+ ``` purescript
25+ fix :: forall l a. (Lazy l) => (l -> l) -> l
26+ ```
27+
28+ ` fix ` defines a value as the fixed point of a function.
29+
30+ The ` Lazy ` instance allows us to generate the result lazily.
31+
32+
33+
You can’t perform that action at this time.
0 commit comments