Skip to content

Commit 0b62cf3

Browse files
Add quick overview for ado notation in Applicative
1 parent 285f934 commit 0b62cf3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/Control/Applicative.purs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,38 @@ import Data.Unit (Unit, unit)
2929
-- | - Composition: `pure (<<<) <*> f <*> g <*> h = f <*> (g <*> h)`
3030
-- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
3131
-- | - Interchange: `u <*> (pure y) = (pure (_ $ y)) <*> u`
32+
-- |
33+
-- | ## Ado Notation
34+
-- |
35+
-- | When using a type that has an instance for `Applicative`, one can use
36+
-- | "ado notation." In short, this code...
37+
-- | ```
38+
-- | foo =
39+
-- | functionThatTakes4Args <$> boxedA
40+
-- | <*> boxedB
41+
-- | <*> boxedUnit
42+
-- | <*> boxedC
43+
-- | where
44+
-- | functionThatTakes4Args a b _ c =
45+
-- | let x = a * a + b
46+
-- | in x + c
47+
-- | ```
48+
-- |
49+
-- | ... can be converted into into "ado notation:"
50+
-- | ```
51+
-- | foo = ado
52+
-- | a <- boxedA
53+
-- | b <- boxedB
54+
-- | boxedUnit
55+
-- | c <- boxedC
56+
-- | let x = a * a + b
57+
-- | in x + c
58+
-- | ```
59+
-- |
60+
-- | Note: if one wants to use "ado notation" but redefine what the in-scope
61+
-- | definitions are for `map`, `apply`, and `pure` in a given context, one can
62+
-- | use "qualified ado notation." This is an intermediate/advanced language
63+
-- | feature not explained here.
3264
class Apply f <= Applicative f where
3365
pure :: forall a. a -> f a
3466

0 commit comments

Comments
 (0)