News for hackers. Stuff that matters.
Re:Comparing OCaml and Standard ML by tomp on Thursday October 23, 2014 @09:17AM (#8497928)
1) Ignore indentation (I intentionally wrote it to deceive, but similar examples could easily appear in real code). 2) `match` cases always bind to the innermost `match` statement. 3) Statement separators (`;`) are tricky.

The correct indentation of the above code is:

  if a > 0 then
    print_endline "a > 0" ;
  match a with
    | 0 -> print_endline "impossible"
    | 2 ->
      match b with
        | 0 -> print_endline "2, 0"
        | _ -> print_endline "2, not 0"
        | 3 -> print_endline "3, something"
        | _ -> print_endline "something, something"
            ;
            print_endline "done"
To have the same meaning as the indentation implies, you would need to add `(...)` or `begin ... end` at the appropriate places.
Re:Comparing OCaml and Standard ML by mercurial on Thursday October 23, 2014 @09:36AM (#8498002)
What would be the corresponding SML? I see how the way SML binds ';' would help here, but would it change anything about the last two badly indented matching? And it seems to provide you with the equivalent footgun if you attempt to do multiple side-effect operations in a match branch, which in my experience you want to do more often than you need to separate matches with ';'.
[deleted]
Re:Comparing OCaml and Standard ML by tomp on Thursday October 23, 2014 @11:39AM (#8498722)
Not in my version of OCaml (OCamlWinPlus v1.9RC4, OCaml version 4.01.0):

  # if false then print_endline "false" ; match () with () -> print_endline "match";;
  match
  - : unit = ()
Re:Comparing OCaml and Standard ML by p4bl0 on Thursday October 23, 2014 @11:43AM (#8498752)
Sorry I realized my mistake and deleted my comment before I saw yours.

FTR, I was saying that the ";" in the `then` clause of the if statement didn't end it, but it actually does. I see that arjunnarayan got this wrong too in his comment here: https://news.ycombinator.com/item?id=8498187.

Re:Comparing OCaml and Standard ML by tel on Thursday October 23, 2014 @09:34AM (#8497993)
I figured the indentation was a lie, but didn't realize you would have to introduce something like begin...end to make it work the way it appears.