DEV Community

Discussion on: Haskell as an alternative to TypeScript

Collapse
leob profile image
leob • Edited on

But can it also be used for the front end (client side, e.g. through Web Assembly? same solution as used by Rust), or are you only talking about replacing JS/TS for the backend (node.js)? That didn't really become clear to me from your article.

I think Haskell has a lot of similarities with Rust, and both can be used in the same scenarios, to replace JS/TS.

Collapse
luismed15971068 profile image
luis medina

I am new to this program, I am learning Haskell for several months, I understand that Rust was very inspired by Haskell. I like both (especially the Syntax of the Rust Lambdas 🤤). Excuse me My English please

Collapse
leob profile image
leob

Yes there are many similarities between Haskell and Rust, and not just superficial ones, it runs pretty deep!

Thread Thread
luismed15971068 profile image
luis medina

Do you know any project where I can practice rust on a personal level?, I mean something that I can show in the future

Thread Thread
leob profile image
leob • Edited on

Sorry no nor really, I was involved in a project which used Rust long ago, but all I did was work through the Rust manual, the project fell by the wayside and I didn't actually build anything ... well I'm sure there's plenty of project ideas around if you google it a bit, using it on the client with Web Assembly seems popular, but Rust is of course also great as a server side language. I don't know, maybe try to build a chat server and client with it?

Thread Thread
luismed15971068 profile image
luis medina

Well, the language I chose to learn in depth is haskell, I heard that the best way to learn in any science is by working on it, that is why I am looking for projects with which to practice 1st Haskell 2nd rust.

Thread Thread
leob profile image
leob

Well, like I said you could try to build a chat app, backend and frontend, that sounds like a nice challenge and should keep you off the street for some time, haha ... and maybe have a look at this link:

users.rust-lang.org/t/recommended-...

Collapse
digitallyinduced profile image
digitallyinduced Author

I personally don't have experience with compiling Haskell to Web Assembly. There seems to be a compiler for this based on ghc here: github.com/tweag/asterius

The easiest for an existing frontend infrastructure is to use Haskell as a replacement for a nodejs backend.

If you want to take a look at IHP, the solution we're doing there is to put as much logic and code on the server, and to use tools such as the included autoRefresh to still achieve highly interactive webapps. You can read more about autoRefresh here: dev.to/digitallyinduced/displaying...

Rust certainly has similarities to Haskell, so if you like Rust, I highly recommend checking out Haskell too, as the differences will at the very least be a good learning opportunity.

Collapse
leob profile image
leob • Edited on

Right, AutoRefresh, this reminds me of old TurboLinks of Rails fame, and more recently of some other "auto Ajax" frameworks which provide for easy and automatic dynamic updates without having to go all out on SPA + API. Can't remember the name of those tools right now, but this definitely seems a trend and a recurring theme recently.

Thread Thread
digitallyinduced profile image
digitallyinduced Author

You might have heard of Phoenix' LiveView. That's certainly very similar.

It's a great pattern - if you haven't used it before I highly recommend trying it out. When I first heard about it I was quite skeptical of whether it could compete with a SPA, but it has certainly convinced me after trying it out.

From the user's point of view there's no difference to be felt really, and as a developer it is SO MUCH nicer.

Thread Thread
leob profile image
leob

You're right ... LiveWire (of Laravel fame) is another one, this really seems to be a popular trend, and for good reasons.

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.