DEV Community

Discussion on: Haskell as an alternative to TypeScript

Collapse
leob profile image
leob • Edited on

I've looked at Haskell in the past, and then at Rust more recently, and I couldn't help but notice how many similarities there are between them (at a conceptual level), even though Rust isn't strictly an FP language.

Thread Thread
digitallyinduced profile image
digitallyinduced Author

There certainly are many similarities. Probably the most popular are the Optional/Maybe and Result/Either types that I also mentioned in the article.

It'd be cool if you could declare functions as using IO/not using IO in Rust too - I think that is a great feature, which has often meant that debugging behavior and making sense of someone else's code got much easier. Though Rust's focus on lower-level programming (compared to Haskell at least) might make it less useful. I don't have much experience with that though - I've always focused on higher-level.

Thread Thread
leob profile image
leob • Edited on

Yes indeed, the way "optional" values are treated - same story for errors/exceptions, both Haskel and Rust have no try/catch, errors are propagated via return values. Rust also seems to utilize "algebraic data types" in the same fashion as Haskell does, whereas other languages would use more of an OO approach with classes/objects. Following along with the Rust tutorial I constantly thought "deja vue" and then "Haskell" !

And both are impressive in how much checking the compiler does for you - if used properly you can achieve a large degree of confidence that your code "does the right thing" even before running it.

The only thing Rust seems to be missing is tail recursion, this also stops it from being seen as a "pure" FP language, typically you'd still write imperative/procedural loops in Rust.