News for hackers. Stuff that matters.
Re:Ask HN: Blind programmers, what can I do to make my code ... by loup-vaillant on Sunday November 18, 2018 @06:21AM (#18479844)
I've just written a little parser I OCaml, and the file goes like this:

  Module declarations                         ( 3 lines)
  Parser type declaration                     ( 1 line )
  Implementation details you don't care about (47 lines)
  Actual grammar                              (20 lines)
In that order. In Haskell, I would probably have put the grammar at the top of the file, so you can get the big picture right away. But the language reads stuff from top to bottom, so I have to put the big picture at the bottom.

An alternative would be separate the details from the grammar, but then I would expose those implementation details in an interface, while in fact the rest of the program is only interested in one function that parses everything.

Or, you could write from bottom to top. It's OCaml, so you know the big picture cannot be at the top. Now a case could be made for a language that reads toplevel statements from bottom to top…

Re:Ask HN: Blind programmers, what can I do to make my code ... by beefhash on Sunday November 18, 2018 @06:48AM (#18479925)
To be fair, C is kind of like that, too. You could move the declarations of static functions to the top, but then you'd still have declarations that prevent you from getting to the real meat.
Re:Ask HN: Blind programmers, what can I do to make my code ... by akavel on Sunday November 18, 2018 @10:50AM (#18480881)
That and poor/nonexistent syntax for macros are about my only 2 serious gripes I have with OCaml. The third was missing multithreading, but IIIC this seems to kinda be workable now with lwt IIUC?