7 ms·
I'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 s
by usrn 4y ago
I'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.
- jolux 4y agoWell I’m not certain that’s the case, it’s my guess because the language has a strong academic background and is also used for teaching purposes, and many functions are written like they would be in a textbook chapter on recursion, with the topmost stack frame holding a pointer to the front of the list, meaning you can blow the stack on large inputs. Why else would it be done that way? Certainly possible I’m missing something.
- yawaramin 4y agoIt's not just about theoretical elegance. The list data structure is massively inefficient. Using lists large enough to blow the stack with recursion is a really good indication that something has gone really wrong and the program design needs rethinking.
- jolux 4y agoThe fact that lists are inefficient doesn’t mean that they should be processed in a maximally inefficient way. I would argue the opposite is true. There’s no practical justification for forcing the compiler to allocate a new stack frame when you can get it to use a jump instead.
- yawaramin 4y agoThere is actually a practical justification–simplicity of the implementation. For a data structure not meant to be used for large datasets, why optimize for that use case? In any case thanks to TRMC landing in OCaml 4.14+, it's a moot question, we'll be able to have our cake and eat it too. Doubtless someone will add the annotation to the standard library soon enough: https://v2.ocaml.org/releases/4.14/manual/tail_mod_cons.html https://v2.ocaml.org/releases/4.14/manual/tail_mod_cons.html
- jolux 4y ago> There is actually a practical justification–simplicity of the implementation. For a function that is going to be written once and called innumerable times, this is a bad justification. You should optimize for the consumers of your library, not for yourself. > For a data structure not meant to be used for large datasets, why optimize for that use case? Because it’s not the job of a standard library to be opinionated about how people use data structures. It’s the standard library’s job to do what is asked of it as efficiently as possible. The best implementation would be specialized for small Ns but they don’t do that either. Good to hear about TRMC, I haven’t been a daily user of OCaml since 4.07, but it’s good to hear that they’re addressing some of these pain points. I still think Core and Base are a better starting point for real-world applications in general.