top | item 18415077

(no title)

hood_syntax | 7 years ago

Just want to note that in Haskell, whitespace syntax _is_ syntactic sugar for brackets etc. I don't recall that being the case for python. Interesting tidbit, some of the big names in the Haskell community have very idiosyncratic coding styles that use the bracket look.

discuss

order

evincarofautumn|7 years ago

Right—that was a source of inspiration for this aspect of my language. The original stated motivation in Haskell’s case was to make it easier to generate Haskell source code without needing to worry about indentation, but I wondered if it could also be helpful for accessibility. (Sadly there’s no way to turn off layout-based syntax in Haskell, and not much interest in such an option last I asked on /r/haskell.)

Explicit delimiters also have an advantage for keyboard navigation, enabling some degree of structural (by-block) movement. I prefer not to use a mouse/trackpad if possible—my main editor is Emacs in a terminal—and I know some people who have trouble using pointing devices or just don’t like switching between keyboard & pointer.

lgas|7 years ago

Can you point out an example or two the bracket style that I could take a look at? Thanks.

evincarofautumn|7 years 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"
      }