git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #913 from japesinator/basic_docs

Docs for some basic functions

commitcd2e91713d88916799825196c2d12e29843435c2 authorPhil Freeman <paf31@cantab.net> dateTue 24 Feb 2015, 13:50 (12 years ago) parentdb7671654803c4
2 files changed+107−13
prelude/README.md+53−6 prelude/prelude.purs+54−7
prelude/README.md+53−6
@@ -12,10 +12,11 @@ otherwise :: Boolean
1212
1313An alias for `true`, which can be useful in guard clauses:
1414
15−E.g.
15+```purescript
16+max x y | x >= y = x
17+ | otherwise = y
18+```
1619
17− max x y | x >= y = x
18− | otherwise = y
1920
2021#### `flip`
2122
@@ -25,6 +26,11 @@ flip :: forall a b c. (a -> b -> c) -> b -> a -> c
2526
2627Flips the order of the arguments to a function of two arguments.
2728
29+```purescript
30+flip const 1 2 = const 2 1 = 2
31+```
32+
33+
2834#### `const`
2935
3036``` purescript
@@ -33,6 +39,11 @@ const :: forall a b. a -> b -> a
3339
3440Returns its first argument and ignores its second.
3541
42+```purescript
43+const 1 "hello" = 1
44+```
45+
46+
3647#### `asTypeOf`
3748
3849``` purescript
@@ -42,9 +53,9 @@ asTypeOf :: forall a. a -> a -> a
4253This function returns its first argument, and can be used to assert type equalities.
4354This can be useful when types are otherwise ambiguous.
4455
45−E.g.
46−
47− main = print $ [] `asTypeOf` [0]
56+```purescript
57+main = print $ [] `asTypeOf` [0]
58+```
4859
4960If instead, we had written `main = print []`, the type of the argument `[]` would have
5061been ambiguous, resulting in a compile-time error.
@@ -111,6 +122,21 @@ instance categoryArr :: Category Prim.Function
111122($) :: forall a b. (a -> b) -> a -> b
112123```
113124
125+Applies a function to its argument
126+
127+```purescript
128+length $ groupBy productCategory $ filter isInStock products
129+```
130+
131+is equivalent to
132+
133+```purescript
134+length (groupBy productCategory (filter isInStock (products)))
135+```
136+
137+`($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
138+`a $ b $ c $ d x` = `a (b (c (d x)))`
139+
114140
115141#### `(#)`
116142
@@ -118,6 +144,21 @@ instance categoryArr :: Category Prim.Function
118144(#) :: forall a b. a -> (a -> b) -> b
119145```
120146
147+Applies a function to its argument
148+
149+```purescript
150+products # groupBy productCategory # filter isInStock # length
151+```
152+
153+is equivalent to
154+
155+```purescript
156+length (groupBy productCategory (filter isInStock (products)))
157+```
158+
159+`(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
160+`x # a # b # c # d` = `(((x a) b) c) d`
161+
121162
122163#### `(:)`
123164
@@ -125,6 +166,12 @@ instance categoryArr :: Category Prim.Function
125166(:) :: forall a. a -> [a] -> [a]
126167```
127168
169+Attaches an element to the front of a list.
170+
171+```purescript
172+1 : [2, 3, 4] = [1, 2, 3, 4]
173+```
174+
128175
129176#### `cons`
130177
prelude/prelude.purs+54−7
@@ -31,27 +31,38 @@ module Prelude
3131
3232 -- | An alias for `true`, which can be useful in guard clauses:
3333 -- |
34− -- | E.g.
34+ -- | ```purescript
35+ -- | max x y | x >= y = x
36+ -- | | otherwise = y
37+ -- | ```
3538 -- |
36− -- | max x y | x >= y = x
37− -- | | otherwise = y
3839 otherwise :: Boolean
3940 otherwise = true
4041
4142 -- | Flips the order of the arguments to a function of two arguments.
43+ -- |
44+ -- | ```purescript
45+ -- | flip const 1 2 = const 2 1 = 2
46+ -- | ```
47+ -- |
4248 flip :: forall a b c. (a -> b -> c) -> b -> a -> c
4349 flip f b a = f a b
4450
4551 -- | Returns its first argument and ignores its second.
52+ -- |
53+ -- | ```purescript
54+ -- | const 1 "hello" = 1
55+ -- | ```
56+ -- |
4657 const :: forall a b. a -> b -> a
4758 const a _ = a
4859
4960 -- | This function returns its first argument, and can be used to assert type equalities.
5061 -- | This can be useful when types are otherwise ambiguous.
5162 -- |
52− -- | E.g.
53− -- |
54− -- | main = print $ [] `asTypeOf` [0]
63+ -- | ```purescript
64+ -- | main = print $ [] `asTypeOf` [0]
65+ -- | ```
5566 -- |
5667 -- | If instead, we had written `main = print []`, the type of the argument `[]` would have
5768 -- | been ambiguous, resulting in a compile-time error.
@@ -98,14 +109,50 @@ module Prelude
98109 infixr 0 $
99110 infixl 0 #
100111
112+ -- | Applies a function to its argument
113+ -- |
114+ -- | ```purescript
115+ -- | length $ groupBy productCategory $ filter isInStock products
116+ -- | ```
117+ -- |
118+ -- | is equivalent to
119+ -- |
120+ -- | ```purescript
121+ -- | length (groupBy productCategory (filter isInStock (products)))
122+ -- | ```
123+ -- |
124+ -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
125+ -- | `a $ b $ c $ d x` = `a (b (c (d x)))`
126+ -- |
101127 ($) :: forall a b. (a -> b) -> a -> b
102128 ($) f x = f x
103129
130+ -- | Applies a function to its argument
131+ -- |
132+ -- | ```purescript
133+ -- | products # groupBy productCategory # filter isInStock # length
134+ -- | ```
135+ -- |
136+ -- | is equivalent to
137+ -- |
138+ -- | ```purescript
139+ -- | length (groupBy productCategory (filter isInStock (products)))
140+ -- | ```
141+ -- |
142+ -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
143+ -- | `x # a # b # c # d` = `(((x a) b) c) d`
144+ -- |
104145 (#) :: forall a b. a -> (a -> b) -> b
105146 (#) x f = f x
106147
107148 infixr 6 :
108149
150+ -- | Attaches an element to the front of a list.
151+ -- |
152+ -- | ```purescript
153+ -- | 1 : [2, 3, 4] = [1, 2, 3, 4]
154+ -- | ```
155+ -- |
109156 (:) :: forall a. a -> [a] -> [a]
110157 (:) = cons
111158
@@ -452,7 +499,7 @@ module Prelude
452499 show LT = "LT"
453500 show GT = "GT"
454501 show EQ = "EQ"
455−
502+
456503 instance semigroupOrdening :: Semigroup Ordering where
457504 (<>) LT _ = LT
458505 (<>) GT _ = GT