Lwt is so useful, why it's not in the stardard lib?

I’m very new to functional programming. I know concepts like Monad, and my first functional or partially functional language that I’m studying is OCaml. I’ve read a lot of the mirage-tcpip stack and it uses Lwt everywhere. Since I’ve seen no other ways to do multithreaded programs and things similar to loops, Lwt seems to me the only way to do it.

Why Lwt is not a part of the OCaml language itself? Is there another way of doing the amazing things Lwt does?

I’m mainly asking because even though I fint Lwt very useful, it looks like it’s cheating. Lwt doesn’t look very functional to me.

I searched the Lwt code and found in github that it contains 23.9% of C code. Is part of this C code used to implement Lwt or the C code is simply for interfacing with system IO?

In other words, does OCaml have native support for thread creation?

The root of my question are tied to verifiability and how reliable is OCaml code that uses Lwt, because if Lwt uses C for threads than it’s very dependent on code that might contain bugs like buffer overflows and null pointers that I want to avoit at all.

Other popular ways include the stdlib Thread module and Async, which is very similar to Lwt.

Well, OCaml isn’t a purely functional language. I don’t think it’s cheating (at what?) to use its non-functional features.

Well, to some extent you have to live with the possibility of bugs. First, you yourself are probably going to write bugs sooner or later, even in purely functional OCaml code. Second, you can avoid C as much as you like in your program, but it’s probably going to run on an operating system written in C, so in principle you could still be affected by pointer bugs. Not to mention that the OCaml runtime itself is already written in C.

As to how reliable Lwt is, I can’t really compare it to other software, but it’s a very popular library that has some very capable developers. I’d be comfortable using it for anything. Certainly the fact that it’s in principle possible to write certain kinds of bug in C doesn’t mean that it’s particularly likely that those bugs exist in Lwt.

8 Likes