git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #913 from japesinator/basic_docs
cd2e917Phil Freeman
prelude/README.md+53−6
@@ -12,10 +12,11 @@ otherwise :: Boolean
12
12
13An alias for `true`, which can be useful in guard clauses:
13An alias for `true`, which can be useful in guard clauses:
14
14
15−E.g.
15+```purescript
16+max x y | x >= y = x
17+ | otherwise = y
18+```
16
19
17− max x y | x >= y = x
18− | otherwise = y
19
20
20#### `flip`
21#### `flip`
21
22
@@ -25,6 +26,11 @@ flip :: forall a b c. (a -> b -> c) -> b -> a -> c
25
26
26Flips the order of the arguments to a function of two arguments.
27Flips the order of the arguments to a function of two arguments.
27
28
29+```purescript
30+flip const 1 2 = const 2 1 = 2
31+```
32+
33+
28#### `const`
34#### `const`
29
35
30``` purescript
36``` purescript
@@ -33,6 +39,11 @@ const :: forall a b. a -> b -> a
33
39
34Returns its first argument and ignores its second.
40Returns its first argument and ignores its second.
35
41
42+```purescript
43+const 1 "hello" = 1
44+```
45+
46+
36#### `asTypeOf`
47#### `asTypeOf`
37
48
38``` purescript
49``` purescript
@@ -42,9 +53,9 @@ asTypeOf :: forall a. a -> a -> a
42This function returns its first argument, and can be used to assert type equalities.
53This function returns its first argument, and can be used to assert type equalities.
43This can be useful when types are otherwise ambiguous.
54This can be useful when types are otherwise ambiguous.
44
55
45−E.g.
56+```purescript
46−
47− main = print $ [] `asTypeOf` [0]
57+main = print $ [] `asTypeOf` [0]
58+```
48
59
49If instead, we had written `main = print []`, the type of the argument `[]` would have
60If instead, we had written `main = print []`, the type of the argument `[]` would have
50been ambiguous, resulting in a compile-time error.
61been ambiguous, resulting in a compile-time error.
@@ -111,6 +122,21 @@ instance categoryArr :: Category Prim.Function
111($) :: forall a b. (a -> b) -> a -> b
122($) :: forall a b. (a -> b) -> a -> b
112```
123```
113
124
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+
114
140
115#### `(#)`
141#### `(#)`
116
142
@@ -118,6 +144,21 @@ instance categoryArr :: Category Prim.Function
118(#) :: forall a b. a -> (a -> b) -> b
144(#) :: forall a b. a -> (a -> b) -> b
119```
145```
120
146
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+
121
162
122#### `(:)`
163#### `(:)`
123
164
@@ -125,6 +166,12 @@ instance categoryArr :: Category Prim.Function
125(:) :: forall a. a -> [a] -> [a]
166(:) :: forall a. a -> [a] -> [a]
126```
167```
127
168
169+Attaches an element to the front of a list.
170+
171+```purescript
172+1 : [2, 3, 4] = [1, 2, 3, 4]
173+```
174+
128
175
129#### `cons`
176#### `cons`
130
177
prelude/prelude.purs+54−7
@@ -31,27 +31,38 @@ module Prelude
31
31
32 -- | An alias for `true`, which can be useful in guard clauses:
32 -- | An alias for `true`, which can be useful in guard clauses:
33 -- |
33 -- |
34− -- | E.g.
34+ -- | ```purescript
35+ -- | max x y | x >= y = x
36+ -- | | otherwise = y
37+ -- | ```
35 -- |
38 -- |
36− -- | max x y | x >= y = x
37− -- | | otherwise = y
38 otherwise :: Boolean
39 otherwise :: Boolean
39 otherwise = true
40 otherwise = true
40
41
41 -- | Flips the order of the arguments to a function of two arguments.
42 -- | 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+ -- |
42 flip :: forall a b c. (a -> b -> c) -> b -> a -> c
48 flip :: forall a b c. (a -> b -> c) -> b -> a -> c
43 flip f b a = f a b
49 flip f b a = f a b
44
50
45 -- | Returns its first argument and ignores its second.
51 -- | Returns its first argument and ignores its second.
52+ -- |
53+ -- | ```purescript
54+ -- | const 1 "hello" = 1
55+ -- | ```
56+ -- |
46 const :: forall a b. a -> b -> a
57 const :: forall a b. a -> b -> a
47 const a _ = a
58 const a _ = a
48
59
49 -- | This function returns its first argument, and can be used to assert type equalities.
60 -- | This function returns its first argument, and can be used to assert type equalities.
50 -- | This can be useful when types are otherwise ambiguous.
61 -- | This can be useful when types are otherwise ambiguous.
51 -- |
62 -- |
52− -- | E.g.
63+ -- | ```purescript
53− -- |
54− -- | main = print $ [] `asTypeOf` [0]
64+ -- | main = print $ [] `asTypeOf` [0]
65+ -- | ```
55 -- |
66 -- |
56 -- | If instead, we had written `main = print []`, the type of the argument `[]` would have
67 -- | If instead, we had written `main = print []`, the type of the argument `[]` would have
57 -- | been ambiguous, resulting in a compile-time error.
68 -- | been ambiguous, resulting in a compile-time error.
@@ -98,14 +109,50 @@ module Prelude
98 infixr 0 $
109 infixr 0 $
99 infixl 0 #
110 infixl 0 #
100
111
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+ -- |
101 ($) :: forall a b. (a -> b) -> a -> b
127 ($) :: forall a b. (a -> b) -> a -> b
102 ($) f x = f x
128 ($) f x = f x
103
129
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+ -- |
104 (#) :: forall a b. a -> (a -> b) -> b
145 (#) :: forall a b. a -> (a -> b) -> b
105 (#) x f = f x
146 (#) x f = f x
106
147
107 infixr 6 :
148 infixr 6 :
108
149
150+ -- | Attaches an element to the front of a list.
151+ -- |
152+ -- | ```purescript
153+ -- | 1 : [2, 3, 4] = [1, 2, 3, 4]
154+ -- | ```
155+ -- |
109 (:) :: forall a. a -> [a] -> [a]
156 (:) :: forall a. a -> [a] -> [a]
110 (:) = cons
157 (:) = cons
111
158
@@ -452,7 +499,7 @@ module Prelude
452 show LT = "LT"
499 show LT = "LT"
453 show GT = "GT"
500 show GT = "GT"
454 show EQ = "EQ"
501 show EQ = "EQ"
455−
502+
456 instance semigroupOrdening :: Semigroup Ordering where
503 instance semigroupOrdening :: Semigroup Ordering where
457 (<>) LT _ = LT
504 (<>) LT _ = LT
458 (<>) GT _ = GT
505 (<>) GT _ = GT