Skip to content

Commit 95ae38f

Browse files
committed
A start on more docs
1 parent 65da234 commit 95ae38f

File tree

6 files changed

+49
-4
lines changed

6 files changed

+49
-4
lines changed

src/Control/Alt.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
-- | This module defines the `Alt` type class
2+
13
module Control.Alt where
24

35
infixl 3 <|>

src/Control/Apply.purs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1+
-- | This module defines helper functions for working with `Apply` instances.
2+
13
module Control.Apply where
24

35
infixl 4 <*
46
infixl 4 *>
57

8+
-- | Combine two effectful actions, keeping only the result of the first.
69
(<*) :: forall a b f. (Apply f) => f a -> f b -> f a
710
(<*) a b = const <$> a <*> b
811

12+
-- | Combine two effectful actions, keeping only the result of the second.
913
(*>) :: forall a b f. (Apply f) => f a -> f b -> f b
1014
(*>) a b = const id <$> a <*> b
1115

16+
-- | Lift a function of two arguments to a function which accepts and returns
17+
-- | values wrapped with the type constructor `f`.
1218
lift2 :: forall a b c f. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
1319
lift2 f a b = f <$> a <*> b
1420

21+
-- | Lift a function of three arguments to a function which accepts and returns
22+
-- | values wrapped with the type constructor `f`.
1523
lift3 :: forall a b c d f. (Apply f) => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
1624
lift3 f a b c = f <$> a <*> b <*> c
1725

26+
-- | Lift a function of four arguments to a function which accepts and returns
27+
-- | values wrapped with the type constructor `f`.
1828
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
1929
lift4 f a b c d = f <$> a <*> b <*> c <*> d
2030

31+
-- | Lift a function of five arguments to a function which accepts and returns
32+
-- | values wrapped with the type constructor `f`.
2133
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
2234
lift5 f a b c d e = f <$> a <*> b <*> c <*> d <*> e
23-
24-
forever :: forall a b f. (Apply f) => f a -> f b
25-
forever a = a *> forever a

src/Control/Comonad.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
-- | This module defines the `Comonad` type class
2+
13
module Control.Comonad where
24

35
import Control.Extend
46

7+
-- | `Comonad` extends the `Extend` class with the `extract` function
8+
-- | which extracts a value, discarding the comonadic context.
9+
-- |
10+
-- | Laws:
11+
-- |
12+
-- | - Left Identity: `extract <<= xs = xs`
13+
-- | - Right Identity: `extract (f <<= xs) = f xs`
514
class (Extend w) <= Comonad w where
615
extract :: forall a. w a -> a

src/Control/Extend.purs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
1+
-- | This module defines the `Extend` type class and associated helper functions
2+
13
module Control.Extend where
24

35
infixl 1 =>>
46
infixr 1 <<=
57
infixr 1 =>=
68
infixr 1 =<=
79

10+
-- | The `Extend` class defines the extension operator `(<<=)`
11+
-- | which extends a local context-dependent computation to
12+
-- | a global computation.
13+
-- |
14+
-- | Laws:
15+
-- |
16+
-- | - Associativity: `extend f <<< extend g = extend (f <<< extend g)`
817
class (Functor w) <= Extend w where
918
(<<=) :: forall b a. (w a -> b) -> w a -> w b
1019

1120
instance extendArr :: (Semigroup w) => Extend ((->) w) where
1221
(<<=) f g w = f \w' -> g (w <> w')
1322

23+
-- | A version of `(<<=)` with its arguments reversed
1424
(=>>) :: forall b a w. (Extend w) => w a -> (w a -> b) -> w b
1525
(=>>) w f = f <<= w
1626

27+
-- | Forwards co-Kleisli composition
1728
(=>=) :: forall b a w c. (Extend w) => (w a -> b) -> (w b -> c) -> w a -> c
1829
(=>=) f g w = g (f <<= w)
1930

31+
-- | Backwards co-Kleisli composition
2032
(=<=) :: forall b a w c. (Extend w) => (w b -> c) -> (w a -> b) -> w a -> c
2133
(=<=) f g w = f (g <<= w)
2234

35+
-- | Duplicate a comonadic context
2336
duplicate :: forall a w. (Extend w) => w a -> w (w a)
2437
duplicate w = id <<= w

src/Control/Functor.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
-- | This module defines helper functions for working with `Functor` instances
2+
13
module Control.Functor where
24

35
infixl 4 <$
46
infixl 4 $>
57

8+
-- | Ignore the return value of a computation, using the specified return value instead
69
(<$) :: forall f a b. (Functor f) => a -> f b -> f a
710
(<$) x f = const x <$> f
811

12+
-- | A version of `(<$)` with its arguments flipped
913
($>) :: forall f a b. (Functor f) => f a -> b -> f b
1014
($>) f x = const x <$> f

src/Control/Monad.purs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1+
-- | This module defines helper functions for working with `Monad` instances
2+
13
module Control.Monad where
24

5+
-- | Perform a monadic action `n` times collecting all of the results
36
replicateM :: forall m a. (Monad m) => Number -> m a -> m [a]
47
replicateM 0 _ = return []
58
replicateM n m = do
69
a <- m
710
as <- replicateM (n - 1) m
811
return (a : as)
912

13+
-- | Perform a fold using a monadic step function
1014
foldM :: forall m a b. (Monad m) => (a -> b -> m a) -> a -> [b] -> m a
1115
foldM _ a [] = return a
1216
foldM f a (b:bs) = f a b >>= \a' -> foldM f a' bs
1317

18+
-- | Perform a monadic action when a condition is true.
1419
when :: forall m. (Monad m) => Boolean -> m Unit -> m Unit
1520
when true m = m
1621
when false _ = return unit
1722

23+
-- | Perform a monadic action unless a condition is true.
1824
unless :: forall m. (Monad m) => Boolean -> m Unit -> m Unit
1925
unless false m = m
2026
unless true _ = return unit
2127

22-
-- | Filter where the predicate returns a monadic Boolean. For example:
28+
-- | Filter where the predicate returns a monadic `Boolean`.
29+
-- |
30+
-- | For example:
2331
-- |
2432
-- | ```purescript
2533
-- | powerSet :: forall a. [a] -> [[a]]

0 commit comments

Comments
 (0)