I’ve been asked what would it take to reduce the exposure to untracked side effects in OCaml. I thought about it, and it would involve getting rid of
ref, arrays, and a lot of functions in the standard library like
print_endline. Pretty dramatic changes.
In my experience with OCaml (through Reason), unchecked side effects (i.e. side effects not being reflected on the type system) have not been that much of an issue. I generally enjoy how easy it is to do things like printing values, and I’m happy that the mutation “escape hatch” is there, because sometimes it just makes sense. The types are also simpler. These are upsides that one has to keep in mind.
In almost every case that I can think of, a side-effectual function generally returns
unit, and at that point one knows there’s something “going on”. Also, mutating values requires to go through a few hoops, which I guess contributes to reduce the amount of side-effectual functions one can find in the wild, in absolute numbers.
So to me, the existing approach makes sense. But I don’t have experience in real life production apps, so I’m curious what folks with more experience think about this, especially considering that effects in Multicore OCaml seem to also be unchecked.
Do you find yourself often wishing that OCaml would track effects on its type system? (supposing that was a realistic scenario).