DEV Community

Cover image for Haskell as an alternative to TypeScript

Haskell as an alternative to TypeScript

digitallyinduced on August 11, 2021

If you've been using TypeScript for your web development, you have understood the value that static typing brings to your productivity. However, Ty...
Collapse
 
leob profile image
leob • Edited

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
 
digitallyinduced profile image
digitallyinduced

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

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

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

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.

Collapse
 
leob profile image
leob • Edited

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.

Collapse
 
the1nternet profile image
Blyler Blones • Edited

Hi, at the end of the first paragraph, you said, "(but APIs work just fine as well)". How do you create api's in IHP? There is no token authentication and the idea of "session" in IHP requires cookies. Also, the "currentUser" in IHP requires cookies. None of that works with an api. So how would you do authentication and getting the current user, etc, if you're using IHP to build a JSON api?

Collapse
 
luismed15971068 profile image
luis medina

Has anyone used Yesod framework ?, I want to start a personal project to practice my haskell skills.

Collapse
 
digitallyinduced profile image
digitallyinduced

Hello Luis, seeing as you want to start learning Haskell (which is great!), I would suggest you start working through IHP's getting started guide (ihp.digitallyinduced.com/Guide/ind...), with which you will build a simple blog website using Haskell. You can then go and build any other website you want with the foundation that you learn there.

You can try building a similar project with Yesod, though we specifically built IHP for people to be more productive faster, and have an easier time getting started than if they were to use Yesod for example.

Good luck on you journey!

Collapse
 
luismed15971068 profile image
luis medina

Thank very much

Thread Thread
 
digitallyinduced profile image
digitallyinduced

No problem!

Collapse
 
lucamug profile image
lucamug

Nice post, thank you for writing it!

Collapse
 
digitallyinduced profile image
digitallyinduced

Thank you for appreciating it!