4 ms·
OCaml is a very powerful language. I'm still discovering new features/patterns everyday. But coming from a background with C/Javascript, the syntax is definitel
by thangngoc89 8y ago
OCaml is a very powerful language. I'm still discovering new features/patterns everyday. But coming from a background with C/Javascript, the syntax is definitely hard to understand. For this particular problem, I think ReasonML has done a very good job of introducing OCaml platform to a wider audience.
Shamelessly plug: I'm working sketch.sh [1] as a learning project for ReasonML. It's a interactive playground (like IPython/Jupyter) for OCaml and ReasonML. It's provide inline types and evaluated values. Give it a try if you're learning OCaml/ReasonML.
[1]: https://sketch.sh https://sketch.sh
- DonaldPShimoda 8y ago> But coming from a background with C/Javascript, the syntax is definitely hard to understand. I work with Haskell fairly regularly, and have experience with a few other languages (Python, Racket, C/C++, Java, etc.), but I definitely agree with this sentiment. I am not a fan of OCaml's syntax at all. I haven't had a chance to check out Reason yet though, so maybe I'll spend some time playing with that soon!
- fhood 8y agoI don't think its syntax is that bad. A bit daunting at first, but it isn't like you need to learn a ton to understand it, so once you have the basics it is pretty readable.
- erokar 8y agoI don't get it. I work day to day with Algol-syntax languages like JavaScript and Java, but have dabbled in ML languages like Elm and Haskell. One of the things I really like about those languages is the syntax -- succinct and clear. What takes time and is hard for me is grasping the semantics and patterns.
- acjohnson55 8y agoI find it pretty clear in simple cases but ambiguities and associativity rules can make interpreting some code a real pain.
- masklinn 8y agoOCaml's syntax is way more verbose and noisy than Haskell's or Elm's. It tends to have longer keywords, more sigils, … and some of the defaults are inconvenient (non-recursive lets) https://wiki.haskell.org/OCaml https://wiki.haskell.org/OCaml has some trivial examples
- diaz 8y agoAs a contrasting opinion I started reading the Ocaml book about something real world and I felt the syntax finally something fresh, beatiful and clean. But I also suffer from having to use scala everyday at work.
- ufo 8y agoAs a big Ocaml fan, the syntax is one of my least favourite aspects of the language. Two things that I find particularly annoying are constructors (which don't have the same syntax as funciton calls) and the multitude of shift-reduce ambiguities that don't do the thing that you want. For example, in the following code the W gets parsed as part of the inner match: match foo with | X -> match bar with | Y -> 1 | Z -> 2 | W -> 3 A lot of this could be remedied by having more expression terminators. ReasonML uses C-like curly braces but even a simple "end" token to close the match expressoin (similar to what Lua does) would already be enough.
- anuragsoni 8y agoThis tripped me up when I was first exploring OCaml. FWIW i've taken to wrapping the nested matches with parenthesis or a begin/end match foo with | X -> (match bar with | Y -> 1 | Z -> 2) | W -> 3 match foo with | X -> begin match bar with | Y -> 1 | Z -> 2 end | W -> 3
- nestorD 8y agoThe indentation sensitive syntax of F# was the solution to me, I would love to see it being integrated into OCaml.
- diaz 8y agoOhh interesting. Didn't get that far yet. But good to know. Is there somekind of place listing these gotchas with the syntax? Seems something good to be aware.
- scns 8y ago