Hacker News new | past | comments | ask | show | jobs | submit login

That's definitely a big difference: OCaml's impurity. Everything exists in a natural (sort of, see below), invisible monad. Let binding can be both pure and impure since impure statements just return plain values upon execution. Furthermore, this is why you have to use (;) all over the place---it's really just the monadic (>>).

Which just goes to show that monads are actually totally natural. Force someone to live in one all of the time and they just forget it's there.

The major thing is that such monads don't play nicely with laziness which drove Haskell to develop (partial) purity the way that it did. This plays out in OCaml where you have to explicitly say exactly when you're forcing lazy thunks which lets the sequencing of operations remain clear.




> Which just goes to show that monads are actually totally natural. Force someone to live in one all of the time and they just forget it's there.

How is that different from saying "mutable state is natural?" I mean, if you don't see the monad, aren't we just right back at imperative programming, or is OCaml implemented with real monads under the cover that make a significant difference to the programming experience? Does it even have a basic effects system?


You can build a basic effect system in the same way you do in Haskell (except without typeclasses you need to be more explicit about which monad you're living inside of). Without syntax sugar this is a bit noisier, of course. Also, without typeclasses transformer stacks are difficult and `mtl`-style transformers are impossible (I think).

So, you can think of OCaml's semantics as living inside of a monad. Or just do it all implicitly by giving basic semantics to ;.

And the way I was speaking I mean to say that "mutable state is natural" too. I don't know that it is universally, but it's certainly something that makes 90% of programmers today feel comfortable.


Does OCaml actually need to apply special semantics to ; or do those already come with strictness? Thanks for the response BTW, this is one of those things I've always wondered about.

> And the way I was speaking I mean to say that "mutable state is natural" too. I don't know that it is universally, but it's certainly something that makes 90% of programmers today feel comfortable.

Well, as long as time and change are considered.


If you look through the SML definition [0] you'll see there is a semantics for declarations separated by ; specifically. It's nothing much more than sequential operation. If you had CBN then sequential effects wouldn't be, but you can define that order explicitly in CBV.

[0] http://sml-family.org/sml97-defn.pdf




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: