4 ms·
OCaml is a great pick for folks wanting to broaden their understanding of prog languages. It has its own set of sensibilities (Fp with some imperative features
by jdonaldson 8y ago
OCaml is a great pick for folks wanting to broaden their understanding of prog languages. It has its own set of sensibilities (Fp with some imperative features thown in, rather than the other way around). It'll force you to get really good with ADTs, which is a good thing.
- krick 8y agoIs there something you'd recommend for a person who wants to learn OCaml? Maybe some book that has great exercises, or just a toy-project example for which OCaml would be a much more "natural" pick than other languages?
- PirateBay 8y agoIf you want to wait a little, the "Real World Ocaml" book is being re-written. It's in beta-ish right but it looks like it would be usable. Though the core language is the same, some of the language metaprogramming features have been totally switched out for other (better) ones. And it uses the modern versions of the Core (note, that is NOT the standard library) library.
- laylomo2 8y agoCheck out dev.realworldocaml.org
- jdonaldson 8y agoYes, this would be the book I would recommend as well. I'll give a bunch of general advice as well: OCaml is pretty old (introduced a year after Java IIUC), and it contains quite a few crusty libraries and programming patterns that come from age. Stick with the latest version you can find through this "modernization" process headed up by JS. I'm on 4.06, which just made immutable strings a default, and broke a ton of libraries. If you run into a broken lib, this recent version change is almost certainly the reason. I strongly recommend 4.06 as a minimum version (if you're not working with legacy code). If there's a library you want to use that is not compatible yet, bug the maintainer to update it. I've run into problems trying to downgrade/upgrade my compiler version + all the tools. I can't recommend doing that, it kinda ruins the experimentation experience. What else can I say? Opam, the package maintainer, is great. There's a great build system, nice IDE support with a set of tools called merlin, and the compiler is super fast. The compiler field-level error messages are generally helpful (typo-fix suggestions), but can be fiendishly opaque if you happen to mess up a match boundary (which can happen easily when mixing in if/then/else statements). Most stuff is google-able, but there's a lot of "line noise" in OCaml function signatures - especially for variant types and labeled arguments. That's harder to search for, so read that section thoroughly in the book.
- brohee 8y agoOCaml was really born as Caml Light, in the early 90s..., it's soon to be 30 years old.
- emmelaich 8y agoYou could argue it started in 1973 as ML https://en.wikipedia.org/wiki/ML_(programming_language) https://en.wikipedia.org/wiki/ML_(programming_language)
- brohee 8y agoYeah but in this case it was really just a name change, the team that worked on Caml Light renaming it OCaml as they added more features, and stopping working on Caml Light shortly after.
- PirateBay 8y agoWell yes, that's the re-write I'm talking about.
- cpeterso 8y agoFacebook's Reason ML might be a more approachable introduction to OCaml concepts. Reason adds a cleaner, more JavaScript-like syntax on top of the OCaml compiler backend. The Reason team's primary focus appears to be compiling Reason/OCaml to JavaScript. It's a nice language, but I'm not sure why they want to pass through a OCaml "middle end" before emitting JavaScript output. Why not just write a direct Reason->JavaScript compiler similar to TypeScript? https://reasonml.github.io/ https://reasonml.github.io/
- donut2d 8y agoReason is just a dialect of OCaml and actually uses the BuckleScript[1] compiler, which before ReasonML, just took OCaml code and transpiling it to JavaScript. It's known for being super fast and generating fast and small JavaScript. But you can compile ReasonML to native binaries as well, not just JavaScript, using the BuckleScript compiler or others like jbuilder[2]. The advantage of having OCaml as the foundation is its excellent type system. It's very mature. I'm relatively new to OCaml, just getting into it this year, but I've found that it forces me to write correct code first. I've been really impressed by it having come from the world of PHP/JavaScript/Swift and others. Personally, I greatly prefer OCaml's syntax to Reason's. I find it much simpler, and less busy. But I know a lot of people are more comfortable with Reason's syntax. I definitely wouldn't call it "cleaner", though. [1]: https://bucklescript.github.io https://bucklescript.github.io [2]: https://jbuilder.readthedocs.io https://jbuilder.readthedocs.io
- thedufer 8y agoThere is no "OCaml middle end". Reason is parsed into the same AST as OCaml, and then passed through the rest of the OCaml compiler.
- deleted 8y ago[deleted]
- donut2d 8y agoI recently got into OCaml (and ReasonML) and wrote a blog post with my experiences. In it I recommend several resources for both languages and explain some stuff that wasn't obvious to me as a beginner: http://donut2d.tumblr.com/post/171205516399/my-experiences-building-a-url-shortener-with-ocaml http://donut2d.tumblr.com/post/171205516399/my-experiences-b... But if nothing else, be sure to check out Real World OCaml[1]. It's pretty great and helped me out a lot getting started. [1]: https://dev.realworldocaml.org https://dev.realworldocaml.org