4 ms·
I have always been interested in OCaml, but I have a genuine question though - last when I looked at seriously at it, the standard library seemed to be a bit of
by z0ltan 9y ago
I have always been interested in OCaml, but I have a genuine question though - last when I looked at seriously at it, the standard library seemed to be a bit of a mess lacking a lot of features. A lot of modern resources seemed to focus on using Jane Street's Core(?) which I would not like to use - I'd rather depend on the standard language for standard features. Is this still a thing, or am I mistaken, or both? Please help! I really would like to use OCaml for a variety of hobby projects, including toy compilers. Which books/resources would you recommend?
- erk__ 9y agoYou could also take a look at F# wich is also a ML derived language so the syntax is very similar to OCaml.
- z0ltan 9y agoI did consider it seriously (especially after watching Scott Wlaschin's Parser Combinators video), but it seems a bit too MS-centric for my liking. Who knows, maybe if learning OCaml doesn't pan out that well, it might be F# for me! :D ... the community seems to be focused, so that's one big advantage.
- xfer 9y agoYou don't need Core, the shipped stdlib is good enough for toy projects. There are other stdlibs like containers and janestreet has split their stdlib into smaller pieces. What's your issue with having to use alternate stdlibs? Regarding books, Real World Ocaml is very well written, although some examples might need tweaking.
- z0ltan 9y agoThanks for the reply! Mostly wondering how people ship stuff if there are different variants of std libs? Say you write your code entirely using one std lib and then try to share it (the code that is) with somebody who uses a different std lib, then the onus of learning the new std lib is entirely on him, right? How does that work for teams then? I know that Jane Street is a big user and so they have considerable influence. That being said, does the std lib (the one bundled with the distro) have enough features (like all the necessary data structures, for instance) to make using it viable in a non-trivial project (off the top of my head, say writing a very simple web server)? If so then, I suppose that's good enough. Any recommendations for learning material? I have a copy of "Practical OCaml", don't really like it. INRIA's materials seem quite substantial, but more like reference.
- xfer 9y agoThe standard stdlib has all useful data structures, mostly the differences are in providing more convenient functions and monadic interfaces that you might have to write yourself, if you didn't use the alternate libraries. There is nothing to "learn" about using another stdlib since most signatures are the same. And they can use a different stdlib if they want. The migration from standard stdlib to alternate ones is fairly trivial(some signatures might differ but typed language means the compiler will catch them for you), so you can start using the stdlib and if you feel like writing some trivial things that should be in the stdlib or you need some advanced data structures you can use the alternate ones. Also you need `lwt`(most people prefer this)/`async` library for writing concurrent programs like a webserver. `Cohttp` is a good library for doing http based client/servers. I strongly recommend `Real world ocaml` and the reference manual is excellent at looking up some new type-level features. Also reading well-known libraries code is an excellent way to learn a language.
- z0ltan 9y agoExcellent. Thanks for the detailed answer - that really helps. To be honest, I want to use OCaml for writing some toy compilers to begin with, and I'm sure that that'll require only the core language, but I would like to use it for more serious projects after that! I'll start off with "Real world OCaml" and see how it goes!
- xfer 9y agoHere is some resource for you to learn from: http://plzoo.andrej.com/ http://plzoo.andrej.com/