11 ms·
Real World OCaml – 2nd Edition (2021)
- a-dub 4y agocool! always happy to see more of this. i learned out of the unpublished french ora book "developing applications with ocaml". (incidentally it was so useful i had a copy shop bind me a custom "book")
- jasperry 4y agoI love that book! I have happy memories of poring over it until I understood signatures and functors. It's available free online as well: https://caml.inria.fr/pub/docs/oreilly-book/html/index.html https://caml.inria.fr/pub/docs/oreilly-book/html/index.html
- iLoveOncall 4y agoWho would be cruel enough to expose the masses to OCaml?
- midoBB 4y agoAt least it ain't Clojure.
- colesantiago 4y agoIt was cruel to expose JS to the masses.
- etaioinshrdlu 4y agoIt seems like Haskell minus the laziness and enforced purity. So really, far less cruel :)
- synaesthesisx 4y agoOne of the early programming classes I took in grad school (taught at Harvard) was focused on OCaml. It was a wild jump but gave me a newfound respect for functional languages. Come to think of it though, I’m convinced the class was sponsored by Jane Street or something.
- percent 4y agoIt's probably a great book, but I think Elixir is better for the masses.
- tgflynn 4y agoI'm a bit surprised to see this making it to the front page. It's been available for a long time and is one of the first resources anyone with an interest in OCaml is likely to encounter. It seems a little like posting a link to cppreference.com.
- pjmlp 4y agoTrue, but it appears to have been updated last year, I for one wasn't aware of it.
- akavel 4y agoEven just "The lucky 10 000" can be already a reason good enough (https://xkcd.com/1053/ https://xkcd.com/1053/)!
- baby 4y agoI wish someone posted that xkcd everytime someone posted a comment like GP
- AceJohnny2 4y agoA more generous interpretation of your sentiment could be: This is a fantastic resource that anyone with a passing interest in the OCaml programming language needs to be aware of.
- rashkov 4y agoThere are constantly new programmers joining the community here. It’s good for quality things to appear regularly.
- throwamon 4y agoI, for one, have the attention span and knowledge organization skills of a Phineas-Gaged goldfish, so it's good to be externally reminded of the existence of good things from time to time.
- usrn 4y agoI'm not a huge fan of this book, if I get a book like this I'd expect it to focus on the standard library and not third party libraries. On the other hand it says "real world" OCaml and as far as I can tell that really is how OCaml used so It's hard to blame the author.
- jolux 4y agoThe standard library is quite small and not very usable for modern production applications. As an example a lot of the list manipulation functions are not tail-recursive because the tail-recursive implementation is less elegant.
- yawaramin 4y agoFor the pedagogical purposes of the book, you don't really need Jane Street Base/Core though. Plus it ignores some pretty widespread community libraries (like Lwt) and pushes its own Jane Street version, Async (which incidentally doesn't support Windows). Anyway, this has all been hashed out before.
- jolux 4y agoYes, I’m aware it’s been hashed out. I was just explaining for the benefit of people not versed in the community why Core is so popular and used in this book, which is focused directly on practical applications of the language.
- yawaramin 4y agoLike I said, you don't need Jane Street Core for the practical application of the language. Many people who are using OCaml practically are not using JSC.
- Zababa 4y ago> As an example a lot of the list manipulation functions are not tail-recursive because the tail-recursive implementation is less elegant. What makes you say this has to do with elegance? This sounds surprising.
- hardwaregeek 4y agoI don't know about everybody else, but I don't find the "list of language features" format that helpful. It's quite dry and it doesn't contextualize how people use these features or what patterns are common. The Guided Tour part at the beginning is the best part IMO. I wish that'd be the entire book. Just a long guided tour of OCaml through the lens of an in depth project, say an interpreter of an ML language.
- anthk 4y agohttps://ocaml.org/about https://ocaml.org/about
- anthk 4y agoAn easier introductory book: https://ocaml-book.com/ https://ocaml-book.com/
- olah_1 4y agoIt was published in 2013, though. Much has changed in terms of tooling, right?
- anthk 4y agoOpam (the CPAN/PIP) counterpart will handle the library cases fine.
- mseri 4y agoYes but it is not really relevant for that book. OCaml has an incredible backward compatibility history, and the linked book is about learning the language itself, not its ecosystem. Things are different for RWO since it relies also on a number of extra tools and libraries which, indeed, change over time (sometimes also substantially)
- ode 4y agoThe OCaml Software Foundation recently gave the author a grant to update the code in the book to the latest release of OCaml, 4.14, and release the new version of it online in HTML and PDF versions. You can read it for free online at https://johnwhitington.net/ocamlfromtheverybeginning/ https://johnwhitington.net/ocamlfromtheverybeginning/
- daenz 4y agoI'm sure this book is an excellent resource (upon skimming the online version, it looks very thorough and well thought out). I think there is some confusion about who "the masses" are though. I don't think a subchapter titled "POLYMORPHIC VARIANT SUBTYPING" is necessarily for—what I consider—"the masses."
- jasperry 4y agoI don't necessarily begrudge the authors for including chapters on advanced topics, it's not like people have to read the whole book. But you raise a valid point. For languages like OCaml that are both large and also veer into PL research territory, some guidance about how many of the advanced topics one needs to understand to be a "real world" programmer could be a big help to the language's adoption.
- rashkov 4y agoYeah that’s a great point. I’ve been writing front-end with reasonml (an ocaml syntax) for a couple years now and I’ve gotten a lot of benefit without writing functors at all.
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]
- mirekrusin 4y agoThis is great live/github based book. Other great resources are Michael R. Clarkson's (from Cornell) videos [0] and book-like format [1]. I took a lot of inspiration from it when playing with rb-trees [2] and functional, ocaml-looking typescript in general [3]. [0] https://www.youtube.com/playlist?list=PLre5AT9JnKShBOPeuiD9b-I4XROIJhkIU https://www.youtube.com/playlist?list=PLre5AT9JnKShBOPeuiD9b... [1] https://cs3110.github.io/textbook/cover.html https://cs3110.github.io/textbook/cover.html [2] https://github.com/preludejs/rb-tree https://github.com/preludejs/rb-tree [3] https://github.com/preludejs https://github.com/preludejs
- seanstrom 4y agoAwesome resources! On a side note have you tried the Rescript [0] or Reason [1] programming languages? They both are based on OCaml and compile to JavaScript. [0] https://rescript-lang.org/ https://rescript-lang.org/ [1] https://reasonml.github.io/ https://reasonml.github.io/
- mirekrusin 4y agoYes, both are very interesting.
- pkilgore 4y agoThe design of OCaml/Reason is the sweet spot of functional programming for me but every time I must deal with Dune after working with the tooling of Go or Rust I want to stab myself in the face repeatedly and I think that maybe that might just be related to the general concept of "masses" + OCaml.
- rashkov 4y agoSorry could you explain your comment some more? Genuinely curious what is bad about dune. Just started using it
- pkilgore 4y agoWe can start with that, upon starting down the road to learning a (IMO great) but very, very different syntax than most other languages in OCaml, Dune then asks you to write a lisp file to do basic configuration and I suspect 90%+ people who want to explore just say "fuck it" the second they internalize this. I'm sure there's a crowd, especially here on HN, that views this as some sort of purity test for the language, but in my opinion it's needlessly obtuse over <insert more readable and traditional and lintable type here> used by modern build systems. Then there's the fact that several `init` commands don't actually fully `init` a project (and up until recently, the very example in OCaml's getting started documentation was broken). Then there's this insanity dune build dune test dune exec # hahaha no, no, this doesn't work. Then you gotta manually tape together crap between opam and dune (and don't get me started on how insane the lockfile situation is -- I swear to god I complained once and someone told me I should learn to use nix!). This is all very fun and yak shave-ey and I generally grin and bear it, but boy do I totally get why most people look at me like I'm a weirdo because I like this language.
- cemerick 4y agoI think there's a lot of strawmen here, many quite analogous to those used to (unfairly IMO) criticize OCaml itself. Complaining about sexprs, when one's baseline is the completely ad-hoc nature of go.mod files, or cargo toml files, is pretty silly. Further, sexprs are a very common general-purpose serialization path for OCaml values, so dune's selection here is hardly arbitrary. Yes, `dune build`, `dune runtest`, and `dune exec ...` do "work", i.e. each command has its semantics, which are pretty extensively documented IMO. Is the complaint that they're not the same commands that one uses with cargo or whatever? You're right that opam and dune used to not interoperate much (or at all), but that has changed a lot in the last year or so, to the point that, _if you want_, you don't have to write opam files at all (i.e. they'll be generated from metadata in your `dune-project` file). Again, well documented, at least IMO: https://dune.readthedocs.io/en/stable/opam.html https://dune.readthedocs.io/en/stable/opam.html The "lockfile situation" is pretty good AFAICT. I've been using them for a year+ with good / expected results. You're right about `dune init` not doing the right things. I believe that's been resolved very recently IIRC, but then again, I can't recall the last language/build tool I used init-like functionality with; I almost always just copy over config/structure from another project I've worked on, and tweak from there. There are absolutely real critiques of dune, but "it's not cargo" or whatever is silly.
- ufo 4y agoNeat! I didn't know there was a 2nd edition. Does anyone know how it differs from the 1st edition?
- clpm4j 4y agoTotally unrelated to the link/book, but sparked a question that I've had for a while (curious to hear any answers) --> when you take an initial look at a programming language that you're completely unfamiliar with, and you glance through the syntax of all the basic constructs, do you ever have a particularly strong reaction (be it negative or positive), and if so have you tried to identify why that might be the case?
- _benj 4y agosuch a good question! I don't think I've ever had a particularly strong guttural reaction to a language, but I'm definitively biased and either see things that I quite like or dislike in a new language I see. As I think about why those are I think one of the biggest reasons is familiarity, it's easy to get comfortable doing one thing and it truly sucks to feel like you don't know anything again (I think somebody called this the curse of knowledge? Idk). Lately I've been intentionally the unknown, or, those languages that I'd look at and be like, "but why!?", for example, why would I want to learn or only use recursion when a for/while has worked for pretty much my whole career? or, following the same functional languages traits, why immutable data? seems like a step backwards? But the thing is that people, quite likely smarter than me, or at least, a lot more familiar with challenges that I'm not familiar with, came up with solutions that diverge from what I know... and I want to know why! Why they came with immutable data or recursion or a language that pretty much everything is a list (LISP)... and the answers are quite surprising and at the same time I feel that joy of discovery that has almost been erased by years in the industry. So when you come across a language that you have strong feelings/opinions about, wearing the shoes of the people using it might be quite enlightening and enjoyable. While I say this, I'm a complete hypocrite because I won't give such courtesy to OOP... but hey, none of us are perfect ;-)
- Hermitian909 4y ago1 - At a high level, I ask myself if the language is pushing me towards the pit of success or the put of failure. More concretely I ask myself "given the class of problems appropriate for this language, are good abstractions easier to create than bad abstractions?". If so, I have a positive reaction. If the reverse is true, and it's easier to make bad abstractions (think early Java where functions were not first class), then I have a negative reaction. 2 - If the language is trying to sell you on a certain paradigm? If so, is there a good escape hatch? This at least means a good FFI like that found in Erlang, but also within the language, OCaml's refs which allow you to write imperative code are a great example. Elm is a language that does this badly, 0.19 removed FFIs and the language is much reduced for it. 3. Is packaging a first class consideration of the language? This is one of the places where say, Rust shines and Python really suffers. I'm going to need packages and if managing them is hard I'm going to get mad. 4. Does the language free me from some class of problems? Big positive. Some languages I've liked: Common Lisp, C, OCaml, Haskell, Python2, Javascript ES5, Racket, Erlang Some languages I've disliked: Java5 and earlier, C++, Go, Python3, PHP circa 1999