|
|
|
|
|
by evincarofautumn
2777 days ago
|
|
Simon Peyton-Jones is (was?) known for writing blocks in “aligned” instead of “hanging” style, with separators in prefix: someFunction =
do { foo
; mx <- bar
; y <- case mx of { Just x -> do { baz
; pure (quux x)
}
; Nothing -> do { fnord
; blurch
}
}
; xyzz y
}
I find it nice enough to read, particularly because it leads to rapidly increasing indentation and consequently discourages deeply nested code, but it’s a bit of a pain to edit & diff. I would write the above like this: someFunction = do
foo
mx <- bar
y <- case mx of
Just x -> do
baz
pure (quux x)
Nothing -> do
fnord
blurch
xyzz y
This prefix delimiter style is actually fairly standard in Haskell not for “do” notation, but for records and lists, since Haskell doesn’t allow a final trailing comma in these structures: list :: [Text]
list =
[ "this"
, "that"
, "the other thing"
]
data Numbers = Numbers
{ numI :: Int
, numF :: Double
, numS :: Text
}
record = Numbers
{ numI = 1
, numF = 1.0
, numS = "one"
}
|
|