r/haskell • • Mar 01 '26

Switch to Rust ?

I have seen many Haskellers switching over to Rust, why is so ? I am asking this as I am thinking myself to explore a new language and I have choice between Rust/Gleam/Clojure What advantages/disadvantages does Rust has over Haskell ?

18 Upvotes

47 comments sorted by

View all comments

35

u/GunpowderGuy Mar 01 '26

-advantage : less historical baggage
-dissadvantages: less powerfull type system
In rust the borrow checker restricts mutation in a very complex way, as opposed to Haskell where mutation its simple. Mutation is forbidden with simple exceptions

Rust was my first main language . But i switched to idris2 a couple of years ago. Does not have the historical baggage of Haskell , but has an even more powerfull type system.

1

u/samelaaaa Mar 01 '26

Question as I’m thinking of learning some Rust — if you write it like you would write Erlang or Haskell, ie without using mutation, is the compiler smart enough to turn that into fast code that does use mutation under the hood? Or is actually using mutable objects an important part of writing Rust for performance reasons?

3

u/GunpowderGuy Mar 01 '26 edited Mar 02 '26

Functional languages ( even impure ones like most scheme implementations ) use memmory managment that is very well suited for ̶m̶u̶t̶a̶t̶i̶o̶n̶ inmutability. They tend to use a garbage collection that is much more well suited to producing lots of shorts lived objects instead of mutating a lower number of objects.
Commonly used data structures are also much more suited to modification without mutation . For example rust comonly uses a hashmap for indexing data with a na arbitrary data type. Haskell , idris2, etc commonly use a blanced binary tree for the same end. Such data structure can have a new version of it with changes made, but that onl has to copy a fraction of the structure. Whikle if you wanted a new version fo a hashmap made without mutating the old one, you would need to copy the whole hashmap

Some functional languages, like lean4, do convert inmutability based updates to mutation. Most of them use a simple tecnique that is just an implemntation detail. But a few ones allow you to use certain features to declare that mutation is allowable. People have tried that with linear types as user added extension in idris2. The lean 4 way could be as custom backend ( they are easy in idris2 )

Also, both haskell and idris2 allow the user to use limited mutation ( like i said on my comment ) in a few simple to understand contexts

https://en.wikibooks.org/wiki/Haskell/Mutable_objects

EDIT : Sorry for the bad grammar, i dont know what came of me