Elm-like languages

Hi,

I have been exploring Elm for a few months now and I really like many things about it. Among other things, I appreciate the way effects are handled. I find it very logical and exemplary for a purely functional language. Now I am wondering which languages are similar to Elm and are also suitable for areas other than frontend development. Which languages would you say feel somewhat like Elm? Which languages do you use yourself? I am most interested in purely functional languages, but that is not a strict requirement.

What do you think e.g. of Roc, Gren, Gleam, F#, Purescript …?

Of course Haskell is also interesting. But my brain refuses to understand how effects are handled in Haskell and what monads really are…
This is what I really like about Elm: Elm is purely functional and all dirty jobs are “commanded” to the runtime. That is simple to understand.

3 Likes

Don’t discount Standard ML and OCaml. Maybe they’re not shiny new and hip, but these are educational and industrial workhorses for decades now.

Standard ML is an elegant, feel-nice language like Elm (though, as a matter of taste, the syntax might not feel as elegant as Elm’s). It being academically focused, available learning/reference material for industrial application will likely be more scarce and less approachable to someone coming from “Elm as a first ML language”.

From a “become a better programmer” standpoint, knowing SML is knowing the languages you mentioned (the “ML family”), and grokking where their inspiration came from. Once you master SML, there are a bunch of interesting ML variants to look into, like ConcurrentML (exploring synchronous message-passing, similar to Erlang), Poly/ML (standalone executables, multi-threading, ffi), MLton (whole program optimization, small and fast standalone executables), etc. IIRC, some Roc optimizations are implementations of research originally implemented and tested on MLton and OCaml.

I vaguely remember one of Evan’s speeches about enjoying Standard ML at school and wanting to convey that feeling of joy to Elm programmers. Might be mis-remembering that, though.

For learning SML, one approach is to go through ML for the Working Programmer. If you happen to prefer a university-level course with video lectures, there’s UW CSE341, among many others.

–
OCaml is a true industry-grade language, with a long history of successes. When I think of what programming languages were used to make stuff that keeps our modern society function, OCaml is certainly there together with C, C++, Erlang. (Albeit no C# and Java–those make our society dysfunction. In any case, don’t want to get into that discussion, this is a personal view).

Again as a matter of taste, OCaml syntax might not feel as elegant as Elm’s, but you can deliver production grade applications and system code with ease. Due to its long history, it offers more than you might need, but you’re not obliged to take it all.

To start exploring OCaml, start with version 5. Expect a bit steeper learning curve and some confusion while the legacy baggage around tooling is cleaned up. OCaml community has a solid momentum in the past few years, with clear focus towards modernizing both the language and the dx and the processes around it. The canonical starting point is ocaml.org.

Plenty of learning resources for OCaml, but most are pre-v5, thus good for language basics, but not necessarily getting up to speed with the latest developments (algebraic effects, eio, …). When learning concurrency, ignore lwt and Async and soldier through eio.

Of course, you won’t be worse off if you first learn SML and then go for OCaml, or do both in parallel.


(History note: F# was originally envisaged “to bring the benefits of OCaml to .NET and .NET to OCaml.”).

4 Likes

Which languages would you say feel somewhat like Elm?

I’d guess Green feels very similar right now as it hasn’t diverged too much yet. The only other language I’d guess is Gleam, though I haven’t written any since it hit 1.0 so I can’t say for certain.

Roc is nice, though it doesn’t feel like Elm to me. F# is cool, but feels more like Ocaml/C# than Elm. Purescript is also cool, but much closer to Haskell than Elm.

Which languages do you use yourself?

I’ve tried many, many language over my career and at this point 90% of what I write is Elm. Then 9% plain JavaScript. The other 1% is anything/everything else.

With tools like Lamdera and elm-pages scripts I can use Elm for full stack & CLI. With Tauri I can use Elm (or other web languages) to build for desktop.

3 Likes

Now I am wondering which languages are similar to Elm and are also suitable for areas other than frontend development.

Besides the ones you mentioned I’d like to add Gleam. It is a backend-first language (its main purpose was to compile to Erlang) inspired by Elm that targets Javascript as well. Lustre is the library that implements the Elm architecture.
Unfortunately the syntax is closer to procedural languages like rust, but for all intents and purposes it’s a purely functional programming language. There are other syntactic quirks here and there but for the most part it’s pleasant.
It also has direct javascript ffi, which is always nice when developing frontend applications.

With Tauri I can use Elm (or other web languages) to build for desktop.

Off topic - what’s your fix/workaround/hack for this issue?

2 Likes

I just don’t user URLs in Tauri because there’s no URL for a user to edit. Just because it’s using HTML and JS internally doesn’t mean it needs to fit everything a browser does.

If you must use URLs, then I think there’s a patch somewhere to be able to use other protocols. Not sure where though.

Gleam is heavily inspired by Elm so it definitely fits into Elm-like languages, but I wanted to clarify this point. It is not a pure functional language, and it explicitly states that in its docs as well:

Gleam is not a pure language and so does not have a command system for managing side-effects. Any function can directly perform side effects and where necessary will manage success and failure using the Result type or other more specific custom types.

Worth looking through this page where that quote is from for a comparison with Elm:

3 Likes

Thank you for all the feedback. Improving my Elm knowledge and exploring elm-pages sounds good to me. In the long run Gren and Gleam (or perhaps OCaml) could be of interest.

1 Like

Gren nails this exactly. It handles effects the exact same way that elm does, but you can also use it to target node, so you can do frontend, fullstack, backend, or cli all with the elm architecture.

It applies the same concepts as elm to the backend really well. Handle HTTP requests with a subscription that sends a message to your update function where you can return a response as a command. Read a file via a task where you handle the success/response result like you would any other. The concepts map really nicely.

There’s about to be a new release of the core and node packages that are bringing some really nice improvements, especially with the FileSystem APIs. @robin.heggelund posted a video where you can see some of that plus see what it looks like to write a node app in gren.

1 Like

I really enjoyed digging into ReScript.

useReducer with RS can feel very Elm-like without all extra glue code. fewer turtles to stack.

1 Like

Elm is an amazing creative tool…

1 Like

Haskell might seem scary but I don’t think it’s the boogeyman people make it out to be. If Elm isn’t breaking your brain, I don’t think Haskell will. If you spent a good week or two learning the basics, you can get plenty out of it. If you’re anything like me, you will find plenty of pieces of Elm will just click on a whole nother level.

Effects are just handled explicitly by your program, usually in your main function, and the results are handed back to you. Instead of the Elm Architechture, you end up having an imperitive shell that uses your functional core. As far as Monads go, you probably are already using them without realizing it. Haskell for Elm developers: giving names to stuff (Part 3 - Monads!)

The downside is that Haskell as a language extends in every direction imaginable, so it’s not exactly a very practical thing o use. I don’t use it very often, but it definately had a solid impact on how I think. I reccomend anyone interested in Haskell to take a month to learn and play with it. Get Programming with Haskell is a great resource.

3 Likes

I made two posts comparing Elm to PureScript and F#:

1 Like

Forturnately there is a package named F# plus that makes it much more ML-like.

I agree.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.