on master help sign in
Tighten examples.
commit3312412476cb1ee587eb335d919b8ed602f17758 authorFacundo Domínguez <facundo.dominguez@tweag.io> dateTue 8 Jan 2019, 12:12 (8 years ago) parent410d2ec
1 file changed+55−83
EXAMPLES.md+55−83
EXAMPLES.md+55−83
@@ -35,38 +35,39 @@ and
3535[Tweag's](https://github.com/tweag/guides/blob/master/style/Haskell.md)
3636style guides.
3737
38−### Function types
39−
40−Type and name fits in one line
41−```Haskell
42−functionName :: (C1, C2) => a -> b -> (a, b)
43−```
38+The following examples show how a program is formatted in
39+multiple lines when the user introduces linebreaks. Otherwise,
40+the programs would be written in one line.
4441
45−Type and name don't fit in one line.
46−```Haskell
47−functionName
48− :: (C1, C2, C3) => a -> b -> c -> d -> (a, b, c, d)
49−```
42+### Function types
5043
51−Context, arguments and result don't fit in one line.
5244```Haskell
5345functionName
54− :: (C1, C2, C3, C4, C5)
55− => a -> b -> c -> d -> (a, b, c, d)
46+ :: (C1, C2, C3)
47+ => a
48+ -> b
49+ -> c
50+ -> d
51+ -> (a, b, c, d)
5652```
5753
58−Arguments and result don't fit in one line.
54+Context
5955```Haskell
6056functionName
61− :: (C1, C2, C3, C4, C5)
57+ :: ( C1
58+ , C2
59+ , C3
60+ , C4
61+ , C5
62+ )
6263 => a
6364 -> b
64− -> (a -> b -> c)
65− -> (c -> d)
65+ -> c
66+ -> d
6667 -> (a, b, c, d)
6768```
6869
69−Arguments don't fit in one line.
70+Arguments
7071```Haskell
7172functionName
7273 :: (C1, C2, C3, C4, C5)
@@ -84,7 +85,6 @@ functionName
8485 -> (a, b, c, d)
8586```
8687
87−Arguments don't fit in one line.
8888```Haskell
8989functionName
9090 :: (C1, C2, C3, C4, C5)
@@ -105,57 +105,48 @@ functionName
105105
106106### Expressions
107107
108−Fits a line.
109−```Haskell
110−f x y z = if x then y else z
111−```
112−
113−Doesn't fit a line.
114108```Haskell
115109f x y z =
116110 if x then longFunctionName y else anotherLongFunctionName z
117111```
118112
119−A lambda fits a line.
120−```Haskell
121−f = \x -> x
122−```
123−
124−A lambda doesn't fit the line.
113+A lambda
125114```Haskell
126115f =
127− \(LongPattern x) ->
128− longFunctionName x
129−```
130−
131−Multiple lambdas don't fit the line.
132−```Haskell
133−f = \(LongPattern x) ->
134− \(LongPattern2 y) ->
135− longFunctionName x
116+ \(LongPattern x) ->
117+ longFunctionName x
136118```
137119
138−The lambda arguments don't fit the line.
120+Multiple lambdas
139121```Haskell
140−f xs =
141− forM xs $ \( LongPattern x
142− , LongPattern2 y
143− ) ->
144− longFunctionName x
122+f =
123+ \(LongPattern x) ->
124+ \(LongPattern2 y) ->
125+ longFunctionName x
145126```
146127
147−The lambda arguments and the preceding expression don't fit the line.
128+Lambda arguments
148129```Haskell
149130f xs =
150− forM xs $
131+ forM xs $
151132 \( LongPattern x
152133 , LongPattern2 y
153− , LongPattern3 z
154134 ) ->
155− longFunctionName x y z
135+ longFunctionName x
136+```
137+
138+There is a do block. Note the change of indentation in the
139+body of `forM`.
140+```Haskell
141+f xs = do
142+ forM xs $
143+ \( LongPattern x
144+ , LongPattern2 y
145+ ) ->
146+ longFunctionName x
156147```
157148
158−`if` expression doesn't fit a line.
149+`if` expression
159150```Haskell
160151f x y z =
161152 if x then
@@ -189,7 +180,7 @@ f x y z = case
189180 Nothing -> functionName x y z
190181```
191182
192−Branches of `case` expression don't fit a line.
183+Branches of `case` expression
193184```Haskell
194185f x y z = case
195186 Just w ->
@@ -198,7 +189,7 @@ f x y z = case
198189 anotherLongFunctionName x y z
199190```
200191
201−A list of arguments doesn't fit a line.
192+A list of arguments
202193```Haskell
203194f
204195 (LongPattern x)
@@ -214,7 +205,7 @@ f x y
214205 | otherwise = False
215206```
216207
217−The right-hand side of guards doesn't fit in a line.
208+The right-hand side of guards
218209```Haskell
219210f x y
220211 | x > y =
@@ -223,7 +214,7 @@ f x y
223214 anotherLongFunctionName x
224215```
225216
226−Long guards don't fit the line.
217+Long guards
227218```Haskell
228219function x y z w y
229220 | x > y
@@ -236,37 +227,18 @@ function x y z w y
236227 anotherLongFunctionName x
237228```
238229
239−Long guards with monadic block
240−```Haskell
241−function x y z w y
242− | x > y
243− , y > z
244− , z > w
245− , w > z
246− = do
247− longFunctionName1 y
248− longFunctionName2 y
249− | otherwise = do
250− anotherLongFunctionName1 x
251− anotherLongFunctionName2 x
252−```
253−
254230### Data type declarations
255231
256−Declaration fits in one line.
257−```Haskell
258−data A = B | C | D
259−```
260−
261−Declaration doesn't fit in one line.
232+Declaration
262233```Haskell
263234data A
264− = B
265− | C
266− | D
267− | E
268− | F
269− | G
235+ = B
236+ | C
237+ | D
238+ | E
239+ | F
240+ | G
270241```
271242
272243TODO: GADTs, record syntax, type families
244+