Dennis Dang

November 28, 2022

5 statically typed functional languages with a possible future

Learn some new concepts in the world of computer science and programming languages by trying these 5 below that’ll take you through algebraic effects, web assembly, pure functional programming (not Haskell), type safety in an actor’s world.

OCaml 5.0

Have you ever heard of algebraic effects? Algebraic effects is a researched but yet-to-be-seen concept used in any major language. OCaml 5 brings algebraic effects to production. Using OCaml effects will be akin to throwing exceptions in today’s common languages. Handler functions, i.e. the parent “try/catch” functions, can catch the effect, perform additional computation, and then potentially pass the work back to the child that threw the effect. It’s similar to Java’s exceptions but those lack the computation continuation that algebraic effects confer. Exceptions today only go one direction as it unwinds a call stack. Is this considered going down or up a stack 🤔?

The immediate benefit to OCaml programmers is a way to write pure functional code in that all side effects can be managed via algebraic effects and their handlers. It is an alternative to Haskell’s monadic approach to managing side effects. It’s yet to be seen but managing side effects with OCaml effects is looking easier to write because you don’t need to understand all the operators and typeclasses required to work with effectful Haskell.
However, the implementation of typed effects is yet to be seen so real evaluation awaits when it arrives.

Roc alpha

Roc hopes to meld the spirit of Elm and Haskell into a new system that brings you Rust-like speed wherever it can, but in a highly integrated tooling package with easy interop with any language that can call C code. This is the most far out to try, but their platform ideas, integrated editor, and focus on easy adoption in a pure functional package makes me hopeful. 


Gleam 0.28

Gleam offers a type safe system that promises easy interop with Erlang and Elixir. Simple as that. The core developer and friends work hard to keep the language easy to learn with a small surface area.

Many love Erlang and Elixir for their easily scalable systems. You add more servers to a cluster, and processes just move around servers seamlessly. You want a batch job that can recover if it fails but doesn’t crash the rest of your system? Throw up a supervisor. But these languages don’t offer static types. I’ve tried but it’s painful to code when I make contractual api changes and have to manually search and update where I used that function.

Great functional alternative to Go. You can spin up a new Phoenix app and call Gleam code. Or just start a simple web server in Gleam directly.

Grain 0.5

Are you interested in web assembly? How about functional programming and web assembly? 
Grain is a modern day language and tooling for web assembly. It’s heavily inspired by OCaml. They offer a wonderfully neat syntax lipstick with a modern cli that includes doc generation and formatter. We can all thank Go, Rust, and Deno for pushing the standards for a integrated tools.

What can you build with grain and wasm? Perhaps try calling other wasm modules from Grain. Or write some logic in Grain, and then call it from your JavaScript in the browser. 

Common alternatives to Grain are Rust, Go, and Assemblyscript.