Is anyone using the effect system for ALL side-effects?

Just curious if this started to become idiomatic in the OCaml ecosystem, to use effects not only for parallelism and concurrency, but for all side-effects, like writing to std/out, database and file access, etc?

We use it on YOCaml: GitHub - xhtmlboi/yocaml: YOCaml is a static site generator, mostly written in OCaml

You can watch the Eff module here: yocaml/lib/core/eff.ml at main · xhtmlboi/yocaml · GitHub

But from my point of view, when I don’t care about continuation (or exception are sufficient to discard the execution) I relay on modules like here: GitHub - xvw/kohai: Kohai is a very simple (but opinionated) timetracker for my personal usage or objects (yeah, I love using OCaml OOP features for dependency injection)

4 Likes

This is so above my head, sorry. :anxious_face_with_sweat:

See also this previous discussion: Curious about real-world uses of the effect system (other than threading) To summarize my response there, I find it useful for managing global mutable state in a functional style. I can’t imagine myself using it for all effectful code, though, at least not for the foreseeable future.

2 Likes

Just a NB, the programming language Elm is kinda working like this, but they call it messages, not effects.

Might be interesting to test a similar paradigm with js_of_ocaml. :slight_smile:

Could you point to some documentation or discussion on that? I am interested, but see nothing obviously relevant on the linked page.

Commands and Subscriptions · An Introduction to Elm is the more specific page.

To model side effects, Elm requires you to send messages as Commands, Cmd MyType. So if you want to make an HTTP request within the browser, your Elm code would typically send a Cmd Msg via the http lib. A command is like an IO type in haskell. Represents possible side effects.

1 Like

There is a lot of project that encode Moore Machine and Mealy Machine at the browser level, based on js_of_ocaml. We can notably mention:

And they use (at different levels of convergence) this notion of pairs between declarative UI rendering, model recalculation by messages, and the use of commands as an alternative channel.

3 Likes

I’m new to Ocaml, so sorry if the question may sound stupid. But why did you need to write all your monadic operators, including return and bind? Is there no out-of-the-box support at the language level, or libraries to do that?

I don’t really have an experience with it, but when reading about functional programming languages I found that Scala has big libraries for effect systems, which are kind of the selling points of the language. Is there nothing comparable to it in Ocaml?

I am aware about GitHub - BinaryAnalysisPlatform/bap: Binary Analysis Platform and GitHub - xvw/preface: Preface is an opinionated library designed to facilitate the handling of recurring functional programming idioms in OCaml. (obviously aware) but our goal was to reduce must as possible dependencies.

For kind of effect abstraction I will mention gr-im.github.io - Basic dependency injection with objects which illustrate what I mean by “yeah, I love using OCaml OOP features for dependency injection”.

5 Likes