Earlier quoted context omitted.
As someone without too much OCaml experience, how do you disambiguate this?
There are two things to remember. The first is the match binding thing that tomp mentions in his reply. The second one is that in OCaml, semicolon is a separator, and not a terminator. In contrast, in C/C++, semicolon is a terminator. If you have an expression, you end it with a ";" just because. This is not the case for OCaml. In OCaml, semicolon is used to separate two sequential expressions where only one expressi…
Comparing OCaml and Standard ML
31–40 of 71 posts
Re: Comparing OCaml and Standard ML
#32Purity is almost used in a pejorative sense throughout the page. If it wasn't for poor library support, I would prefer using SML to OCaml. SML is syntactically simpler and both SML/NJ and MLton have a lot to offer that I haven't yet found with OCaml. I think one of the biggest mistakes in the life cycle of SML was premature specification. As a result of the language definition, SML has stagnated for almost 20 years.…
I agree completely with your library statements. > I think one of the biggest mistakes in the life cycle of SML was premature specification. I disagree. There were some earlier Successor ML efforts ~10 years ago (see: http://successor-ml.org/index.php?title=Main_Page ), but as I understand it, there was agreement on many of the small issues but larger challenges reaching consensus on bigger changes. You can see some…
Re: Comparing OCaml and Standard ML
#33Small update: recent versions of OCaml have immutable strings too. It also miss mention of package manager (OCaml has Opam, which is awesome, I don't know about SML). And ocamlbuild is missing from the build tools section.
Out of curiosity, why do you think Opam is awesome? I recently had to install a few OCaml projects and I had a hard time dealing with opam and ocamlfind (both on mac os and a linux VM). I suppose it's fine once everything is properly set up. I have the impression that the OCaml world has seen a lot of changes recently with a lot of complexity added.
Re: Comparing OCaml and Standard ML
#34Small update: recent versions of OCaml have immutable strings too. It also miss mention of package manager (OCaml has Opam, which is awesome, I don't know about SML). And ocamlbuild is missing from the build tools section.
My only reservation with Ocaml is that there does not exist a package management system for windows or even cygwin. I cannot understand why OPAM takes so much to work on Cygwin. I like SML but it still does not have a good set of libraries. I understand that these projects are sort of resources but supporting cygwin well should be easier than mingw or VS.
Apparently it works with WOBI, an OCaml distribution for Windows. I haven't tried it though.
When on Windows I just go for F#.
Re: Comparing OCaml and Standard ML
#35Earlier quoted context omitted.
As someone without too much OCaml experience, how do you disambiguate this?
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_endli…
Re: Comparing OCaml and Standard ML
#36Earlier quoted context omitted.
Any decent programming editor will be able to indent that properly and you will see the problem. Also, I agree that it is a bit ugly but it's not that complicated to understand how the match syntax works. Adding a "begin" and an "end" in this code is simple enough :).
It's not just the match syntax; it's also the `;` expression separator. > Any decent programming editor will be able to indent that properly and you will see the problem. This seems like a weak excuse. In particular, I could turn it around and say, "any decent programming language should be writable without an editor". Also, the issue isn't just reading, it's writing too - it's much harder to foresee/plan all the `be…
Fair enough, but for the ';', as others explained meanwhile, I think it's pretty simple to understand, it's just that we are not used to it because of C syntax.
EDIT: actually, you are right about ';', it is confusing when I think about it: it does not have the same behavior in a branch of a `match` and in the branch of an `if`… I wonder how I never had problem with that before.
Re: Comparing OCaml and Standard ML
#37Earlier quoted context omitted.
Do you share the development anywhere online? Are you using Menhir? I could maybe help you if you're having any troubles with the parser, I've been working on many interesting and hard (LA)LR parser issues in the past few months. What will the syntax be like, any existing language, maybe like Julia?
I don't have the code publicly available yet, but all the development will happen openly on GitHub. I estimate to prepare a minimal working compiler in the next weeks. I've been thinking a lot about how to perform the parsing. I believe it's important to have a complete metaprogramming system (with code macros and quasiquotations) with all the basic language primitives defined in the language itself. So standard pars…
Re: Comparing OCaml and Standard ML
#38Earlier quoted context omitted.
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_endli…
[deleted]
# if false then print_endline "false" ; match () with () -> print_endline "match";;
match
- : unit = ()Re: Comparing OCaml and Standard ML
#39Earlier quoted context omitted.
[deleted]
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 = ()
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
#40Earlier quoted context omitted.
As someone without too much OCaml experience, how do you disambiguate this?
There are two things to remember. The first is the match binding thing that tomp mentions in his reply. The second one is that in OCaml, semicolon is a separator, and not a terminator. In contrast, in C/C++, semicolon is a terminator. If you have an expression, you end it with a ";" just because. This is not the case for OCaml. In OCaml, semicolon is used to separate two sequential expressions where only one expressi…
if then ; else
Actually, this will not work, I was also confused by it. # if true then (); 1 else 2;;
Error: Parse error: [str_item] or ";;" expected (in [top_phrase])
# if true then begin (); 1 end else 2;;
- : int = 1
# if true then ((); 1) else 2;;
- : int = 1
The confusion comes from the fact that it doesn't behave the same way in match expressions: # match true with | true -> (); 1 | false -> 2;;
- : int = 1