@@ -60,7 +60,13 @@ out the rest, the whole library still keeps compiling.
60
60
Line Length
61
61
-----------
62
62
63
- Maximum 80 columns. This is very helpful when seeing diffs side by side.
63
+ Maximum 80 columns. This is very helpful when seeing diffs side by side.
64
+
65
+ Below, we have listed styles for single line and multi line cases. The
66
+ single line case is used when the whole construct fits into a single
67
+ line and multi line when it becomes longer than 80 columns and needs to
68
+ be broken into more than one line. In some cases, single line is meant
69
+ for a nested construct rather than for the outer one.
64
70
65
71
Indentation
66
72
-----------
@@ -122,14 +128,15 @@ Single line::
122
128
123
129
import Control.Concurrent (killThread, myThreadId, takeMVar, threadDelay)
124
130
125
- Multi line::
131
+ Multi line, list style to avoid rearrangement when adding new items ::
126
132
127
133
import Control.Exception
128
- (assert, Exception, SomeException, AsyncException, fromException, mask_)
129
-
130
- import Prelude hiding
131
- (map, mapM, mapM_, repeat, foldr, last, take, filter, takeWhile, drop
132
- , concatMap, replicate, enumFromTo, concat, reverse, iterate, splitAt
134
+ ( assert
135
+ , Exception
136
+ , SomeException
137
+ , AsyncException
138
+ , fromException
139
+ , mask_
133
140
)
134
141
135
142
Delineating Sections
@@ -217,6 +224,34 @@ Multi line::
217
224
, Three
218
225
)
219
226
227
+ Nested::
228
+
229
+ list =
230
+ [ Group1
231
+ [ One
232
+ , Two
233
+ , Three
234
+ ]
235
+ , Group2
236
+ [ One
237
+ , Two
238
+ , Three
239
+ ]
240
+ ]
241
+
242
+ tuple =
243
+ (
244
+ ( One
245
+ , Two
246
+ , Three
247
+ )
248
+ ,
249
+ ( One
250
+ , Two
251
+ , Three
252
+ )
253
+ )
254
+
220
255
Expressions
221
256
-----------
222
257
@@ -324,7 +359,8 @@ Cascading ::
324
359
else v
325
360
326
361
Its preferable to not mix single line and multi-line formats, but sometimes you
327
- can, use your judgement.
362
+ can, especially the first or last line could be in a single line format even if
363
+ the rest are in multiline format.
328
364
329
365
Variable Naming
330
366
---------------
@@ -566,12 +602,30 @@ Function Application & Composition
566
602
567
603
Single line::
568
604
605
+ y = f (g (h x))
569
606
y = f $ g $ h x
570
607
y = h x & g & f
571
608
k = f . g . h
572
609
573
610
Multi line::
574
611
612
+ lookup e m =
613
+ foldrM
614
+ (\(a, b) xs -> if e == a then return (Just b) else xs)
615
+ (return Nothing)
616
+ m
617
+
618
+ func =
619
+ S.drain
620
+ (encodeLatin1Lax
621
+ (S.concatUnfold A.read
622
+ (S.concatMapWith parallel use
623
+ (S.unfold TCP.acceptOnPort 8090
624
+ )
625
+ )
626
+ )
627
+ )
628
+
575
629
func =
576
630
( S.drain
577
631
$ encodeLatin1Lax
@@ -580,6 +634,14 @@ Multi line::
580
634
$ S.unfold TCP.acceptOnPort 8090
581
635
)
582
636
637
+ func =
638
+ ( S.drain
639
+ . encodeLatin1Lax
640
+ . S.concatUnfold A.read
641
+ . S.concatMapWith parallel use
642
+ . S.unfold TCP.acceptOnPort
643
+ ) 8090
644
+
583
645
Multi line in `do ` block::
584
646
585
647
func = do
@@ -591,6 +653,27 @@ Multi line in `do` block::
591
653
& S.drain
592
654
)
593
655
656
+ Multi line with lambdas, the last application could be a multi line expr::
657
+
658
+ return $ Skip $
659
+ if done
660
+ then (FromSVarDone sv)
661
+ else (FromSVarRead sv)
662
+
663
+ f x =
664
+ g $ h $ \y -> do
665
+ putStrLn "hello "
666
+ return y
667
+
668
+ -- alternatively it can be formatted like a sequence
669
+ f x =
670
+ ( g
671
+ $ h
672
+ $ \y -> do
673
+ putStrLn "hello "
674
+ return y
675
+ )
676
+
594
677
Haddock
595
678
-------
596
679
@@ -621,3 +704,8 @@ Haddock
621
704
fromAddr# :: Int -> Addr# -> IO (Array Word8)
622
705
fromAddr# n addr# = do
623
706
707
+ References
708
+ ----------
709
+
710
+ * https://www.joachim-breitner.de/blog/739-Avoid_the_dilemma_of_the_trailing_comma
711
+ * https://stackoverflow.com/questions/10483635/why-do-lots-of-programmers-move-commas-to-the-next-line
0 commit comments