5 ms·
Can you provide an example of the things, OCaml makes more complicated and explain which languages you compare it to? I guess it's quite different in comparison
by phaer 8y ago
Can you provide an example of the things, OCaml makes more complicated and explain which languages you compare it to? I guess it's quite different in comparison to C, C++ or maybe Rust than to other garbage-collected 'system programming' languages like Go?
- pasabagi 8y agoI think he's getting at the distinction between operational and denotational semantics. Presumably, operational semantics are a better fit for systems programming, because if you need to imagine what the computer is actually doing (Linus's comments about why he likes C comes to mind). Ocaml is more in a denotational direction than C - although to be honest, I don't ultimately understand the distinction, given that C relates to an abstract machine that is not all that similar to most machines today.
- ernst_klim 8y agoBut monads are a version of small-stem semantics. And the write linker, so something that operates low-level data, not an actual low-level code, OCaml is a great language for that. Take a look at BAP, it heavily uses OCaml features and implements a beautiful design: https://github.com/BinaryAnalysisPlatform/bap https://github.com/BinaryAnalysisPlatform/bap https://binaryanalysisplatform.github.io/bap/api/master/argot_index.html https://binaryanalysisplatform.github.io/bap/api/master/argo... I'm not convinced that OCaml is unsuitable for such tasks.
- pasabagi 8y agoI don't know enough to judge. I do feel that people generally (especially functional people) overestimate the overlap between maths and programming - I think maths is just the most useful toolset in programming, but isn't really what programming is about. So I can see why people feel C, with most of its metaphors derived from how (old) machines work, is perhaps a better fit for fundamental stuff than functional languages, that tend to derive their metaphors from maths. That said, I don't know if this makes sense in a out-of-order, parallel world. I think as an organizational schema, imagining a machine that's doing things works better when that machine is relatively intuitive and simple.
- ernst_klim 8y ago> maths is just the most useful toolset in programming, but isn't really what programming is about. It's not about maths, actually. You don't need to understand much math to comprehend monads, you need math only to reason about some properties and formal verification. So think of monads as of codification of imperative effectful computations in a more general way. I really like that example: https://binaryanalysisplatform.github.io/bap/api/master/Monads.Std.html https://binaryanalysisplatform.github.io/bap/api/master/Mona... What monad's bind does is just binding a step of computation to the rest of computation, so it is nothing new but a small step (operational) semantics written explicitly. That's why haskell has this do sugar that looks like as an imperative computation. Because it is a first class imperative computation. Do you want first class features (functions, computations, effects) or features baked into the language is a subjective matter of course.
- pasabagi 8y agoThat's fascinating, actually! Thanks for sharing. I'm not particularly partial to either side of the discussion - I like engineering considerations, and I also like really abstract computer science. I think people tend to specialize and polarize in a way that's more reflective of social structure than technical possibilities, which is a shame.
- emersion 8y agoHere are a few examples: - Inferred types: you're constantly wondering "what is the type of this variable?". Type errors occur far from where the real type error is. Annotating is complicated because you're often dealing with complicated types (with nested tuples for instance). - Using higher-order functions: often you'll see a function with nested functions in it [1], or some functional list processing function like "unzip" being used [2]. This increases the code complexity a lot ("what does unzip do again?"). - Using monads: yet another distraction from what's really happening. It forces you to write nested functions and doesn't play well with conditions [3]. Also various people use monadic operators way weirder than >>= and all of this becomes really hard to read. - Using functional-friendly data structures: the linker is using immutable lists of optional bytes to represent memory images, because this is idiomatic in OCaml. However this is slow and inefficient as hell. Really, I can't load a 60MiB binary because the linker runs out of memory and is killed by the kernel on machine with 6GiB of RAM. Also, just linking hello-world takes ages. - Designing functional loops: when the loop you want isn't in your stdlib, you first need to create a recursive function, and then make sure all recursive calls are tail calls otherwise you blow up your stack. The result is usually not very fun to read. tl;dr: the C language is small, the OCaml language is not, and when you're dealing with complicated stuff you really don't _need_ more complexity from the language itself. James Mickens explains this (among other things) in his essay. [1]: https://github.com/rems-project/linksem/blob/master/src/link.lem#L820 https://github.com/rems-project/linksem/blob/master/src/link... [2]: https://github.com/rems-project/linksem/blob/master/src/link.lem#L341 https://github.com/rems-project/linksem/blob/master/src/link... [3]: https://github.com/emersion/linksem/blob/54c3a8430e621198653744738933cdbea3151866/src/main_load.lem#L230 https://github.com/emersion/linksem/blob/54c3a8430e621198653... (Note: set the syntax highlighting to "OCaml" when trying to read this source code) EDIT: list formatting EDIT 2: grammar
- ernst_klim 8y ago>the linker is using immutable lists of optional bytes to represent memory images Why would you use linked list instead of Bytes, Bigarrays or Arrays? You are doing it wrong, take a look at BAP's memory representation: https://github.com/BinaryAnalysisPlatform/bap/tree/master/lib/bap_image https://github.com/BinaryAnalysisPlatform/bap/tree/master/li... https://binaryanalysisplatform.github.io/bap/api/master/argot_index.html https://binaryanalysisplatform.github.io/bap/api/master/argo... Looked at your code, damn it's bad, I'd really suggest to dive into BAP sources and documentation a bit to understand how to write OCaml. It feels like you are trying to write in OCaml as in some different language, Haskell maybe, not using modules and functors. Reminds me how J people write C. You could write `fun x y z -> ...` instead of `fun x -> fun y -> fun z -> ...`, it's also better to write signatures (with docstrings) in separate .mli files (much easier to read and generate docs), if you use monads like maybe (why not result) and option, it would be much more convenient to use bind operators instead of `match ... | None -> None`