r/functionalprogramming • u/ScientificBeastMode • Jan 04 '25
FP I tried the Roc programming language for a couple of weeks and it’s now my all-time favorite language.
And I say this as an extreme polyglot programmer. I’ve used JavaScript, Python, C, C#, F#, OCaml, Haskell, PureScript, ReasonML/ReScript, Rust, Go, SML, Clojure, Scala, and probably some others, many of which I used at work at various times.
Prior to trying Roc, my favorite language was definitely OCaml. OCaml is fast and relatively easy to build stuff with, and it doesn’t force you to only use pure functions. It’s just a nice pragmatic “get shit done” language which is nice to work with and very expressive.
Roc does this better IMO. It’s a pure functional language, which I thought I wouldn’t like, but it honestly doesn’t get in my way. It beats Haskell IMO because it’s faster and has more predictable performance characteristics, but more importantly it’s simpler. It doesn’t end up in type-level abstraction to the heavens. I just write my functions with straightforward types and go on my way.
There are two reasons I think I really love Roc more than other languages.
First of all, the variant types (called “tags” in Roc) are basically like OCaml’s polymorphic variants. You can define a “closed” set of variants in a type definition, or you can make it “open”/extensible. More importantly they are global types. I can just return a Document Str type from a function and it will “just work” with third party code that also accepts Document Str without having to qualify it with a module namespace. You don’t even have to define them. Just use them and they just exist everywhere for any function. It’s so nice to quickly bang out a script without much type-level ceremony. It reminds me of TypeScript but with no need for a type declaration.
Polymorphic variants are my favorite language feature from OCaml, but Roc just makes that the only type of variant you get. It’s just a simpler language design.
Second, the platform-specific environment is amazing. You can use a “basic CLI” platform or a “basic web server” platform, or even embedded platforms. Anyone can just define a platform API and wire it up to the host code, and then you can call those functions from Roc. The calls to these platform-specific functions are wrapped in a Task type (similar to Haskell’s IO), which is basically just an async Result type. It’s simple to use and has a clean async-await style syntax sugar that looks super clean.
Imagine a simpler version of Haskell (closer to Elm, actually) that can easily run on an embedded system and beat OCaml and Go on performance in many cases without much perf-related contortions in your code. Just write straightforward functional code and it runs at blazing speeds.
The only problems I can identify with Roc so far are (1) the lack of some nicer higher-level string niceties (like a dedicated Char type), (2) it has a smaller package ecosystem than more established languages like Haskell, (3) the LSP is minimal and doesn’t provide type info as far as I can tell, and (4) it still has some minor compiler bugs to iron out.
So it’s definitely not production-ready for business use case IMO, but I can see it easily getting there. I’m currently writing a compiler in Roc, so it’s useful enough now for that purpose.
Oh yeah, and it’s incredibly easy to set up and get your code building. I did it in less than 10 minutes just following the instructions for my Mac. Basically zero configuration process.
You should try it out!
29
u/capacman Jan 04 '25
I still waiting for a beta or rc version
16
u/Kreeps277 Jan 04 '25
This is my sign to give it try, have been lurking the Roc homepage but never tried it
13
u/mckahz Jan 05 '25
The reason why strings are represented like that, i.e. without an underlying "char" type, is for a lot of reasons.
Importantly- it's not a missing feature. It's designed like that deliberately. The main problem is that when you have unicode the concept of a "character" doesn't really work. Is it the bytes in the string? Is it the grapheme clusters?
The main idea is that if you're dealing with a string and you don't have the function you want on it, then you're probably better of using a different representation like a list of bytes.
A lot of Roc's design works like that though, and sometimes it's annoying (I mean, finding the number of ASCII characters in a string with only ASCII looks like
str |> Str.toUtf8 |> Result.withDefault [] |> List.lenwhich is way more cumbersome thanstr |> Str.len) but you're usually rewarded when you try and work with the language.6
u/jimmux Jan 05 '25
I've only read the docs for Roc, but between the platform approach and in-place updates of immutable data (where safe), there's potential for it to be a great game engine language.
5
u/XDracam Jan 05 '25
I've been following roc for quite a while, but the lack of namespaces for tags always bothered me. I definitely do not want some random
Duration Intto be compatible with any library that happens to declare anotherDuration Int, especially when one is in "ticks" and the other in milliseconds. Maybe this worry isn't warranted, but I haven't found a good reason to use roc yet so I can't know for sure.11
u/xiaodaireddit Jan 04 '25
Hi Richard Feldman
4
u/avillega Jan 05 '25
I did try roc a few months ago. Was trying to build a simple web server that took some json input with some dynamic fields and I wanted to encode them as a Dict on roc, it was impossible at least with my knowledge of the language at the time.
4
u/pthierry Jan 05 '25
I have loved Elm for its simplicity and I suspect in the near future, Roc will become my go-to language to have people make first contact with pure FP.
But I also expect I'll have the same experience with Roc as with Elm: I'll miss the power of Haskell. Many people rant about the complexities of Haskell but they are the price of its power and I use that power all the time.
3
u/stuxnet_v2 Jan 05 '25 edited Jan 05 '25
Roc is getting some basic imperative features like for loops and variable reassignment too, described in this recent talk https://youtu.be/42TUAKhzlRI - similar to the trend of imperative languages adding functional features. It’s cool how they’re really taking advantage of being in alpha and heavily incorporating feedback from users.
Edit: looks like there are even more feedback-driven changes since I last checked in: switching from
f x ytof(x, y), rust-like lambda syntax|a, b| expr, snake_case over pascalCase.6
u/PriorTrick Jan 05 '25
Have similar language experience as you, always was a big ocaml fan. Just started playing with Roc after seeing your post, and at a glance I’m really liking it. Thanks for sharing, hope to see this continue to mature
6
u/mtelesha Jan 05 '25
I am still stuck in my love for Racket. Seems like Roc is a first cousin.
5
u/mister_drgn Jan 04 '25
Coming from Clojure and having casually tried out languages like OCaml, I like it. Tags are an interesting cross between lisp-like keywords and enums. The two biggest drawbacks, to me, are 1) the language is a bit feature-poor compared to other compiled functional languages, both because it’s new and because of design decisions discussed in the faq on the website; and 2) the language is mostly quite intuitive, but type signatures are not. That’s somewhat just a matter of learning, but when I asked on their zulip page, people admitted that * is problematic, since it seems like a wild card but isn’t.
Have you messed with Abilities at all? They seem to me like a key language feature, similar to interfaces/protocols/traits in other languages (not type classes, without hkts), but they’re buried at the end of the documentation, so I don’t know how stable they are right now.
5
u/[deleted] Jan 05 '25
How's package management? Easy builds are one of the big differentiating factor for things like Rust and Go.
4
u/dev_l1x_be Jun 03 '26
Did you stick to it?
4
u/[deleted] Jun 03 '25
In what degree the comment you mention about Roc are also valid for Koka Language?
3
u/iamevpo Jan 05 '25
Does Roc also provide an option to compile on one platform for another? I have been watching Developer Voices podcast where the host interviewed creator of Roc Richard Feldman and all of these podcasts on several new programming languages are superb - they tell both a technical and a personal story and the host is great.
Here is the one about Roc:
https://youtu.be/DzhIprQan68?si=0HrsclbF2IcsIzuW
3
u/Altruistic_Shake_723 Jan 21 '25
Elm was my favorite syntax ever and I've been watching videos on Roc all day. Feldman is/was so into Elm I probably wouldn't have known about it if it wasn't for him. So they started the compiler in Rust and switched to Zig?
The type inference looks amazing.
1
u/[deleted] Jun 25 '25
[removed] — view removed comment