3 ms·
Can you point out an example or two the bracket style that I could take a look at? Thanks.
by lgas 8y ago
Can you point out an example or two the bracket style that I could take a look at? Thanks.
- hood_syntax 8y agohttps://en.wikibooks.org/wiki/Haskell/Indentation#Explicit_characters_in_place_of_indentation https://en.wikibooks.org/wiki/Haskell/Indentation#Explicit_c... Probably the simplest good example, gives rules for translating between styles
- evincarofautumn 8y agoSimon 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" }