Re:Ask HN: How should a programming language accommodate dis...
by lgas on Friday November 09, 2018 @02:23PM
(#18417102)
Can you point out an example or two the bracket style that I could take a look at? Thanks.
[ Parent
| on HN ]
Re:Ask HN: How should a programming language accommodate dis...
by evincarofautumn on Saturday November 10, 2018 @03:51AM
(#18420519)
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"
}
Re:Ask HN: How should a programming language accommodate dis...
by hood_syntax on Friday November 09, 2018 @03:59PM
(#18417972)
https://en.wikibooks.org/wiki/Haskell/Indentation#Explicit_c...
Probably the simplest good example, gives rules for translating between styles