Transpiling a large PureScript codebase into Haskell, part 0: What? Why?

May 5, 2021
Written by Artyom Kazak @ Monadfix

What? Why?

About a year ago, Monadfix has been hired by Juspay — a large fintech company in India — to assist with porting a large backend codebase from PureScript into Haskell. PureScript is great, but Haskell is great and also fast, so that's a win. Speed is important for a backend. Speed directly translates into money.

We have written a PureScript to Haskell transpiler, called Nau. Its output is already handling payments in production.

The requirements were:

  • The original codebase is a moving target. We can't freeze it and spend a month manually fixing the transpiled code.
  • The transpiled codebase should have the same behavior. Merchants and gateways are relying on implementation details of the codebase, and we can't change them. Even changing the way numbers are formatted can lead to trouble.
  • The transpiled codebase should be of high quality. The end goal is not merely a working binary. The end goal is throwing away the old codebase and moving to Haskell entirely.

This was fun.

A super rough outline of this series

Juspay has kindly agreed to let us write about the transpiler (which is currently not open source), and oh boy are we going to talk about it. Here's what I have in mind:

  • The overall pipeline: parsing, syntactic and semantic transformations, and pretty-printing
  • The pitfalls of calling JavaScript from Haskell
  • Writing a custom name resolver for PureScript
  • Reverse-engineering the runtime representation of PureScript values
  • Replicating the PureScript JSON library with generics-sop
  • Adapting PureScript's row types to Haskell
  • Porting code from one database framework to an entirely different framework (and writing a custom DSL on top of Beam in the process — we'll discuss the notoriously tricky Beam types, too)

Maybe more things. I could have forgotten some. Stay tuned for the future posts. Subscribe to our Twitter. Subscribe to Juspay's Twitter. Subscribe to everyone's Twitter.

A bit more about Juspay

Juspay doesn't often get talked about in the Haskell community, and it's a shame.

I asked for a blog post blurb, and got this:

Juspay is a leading fintech company in India with over 5Bn txn processed, 150Mn SDK installs & $27Mn in funding. 

And we’re hiring. Please check out the open positions here:

And yep! All is true. They are a major fintech company (e.g. they are Amazon's payment processor in India). They are one of the title sponsors of Functional Conf. They are involved in a lot of various projects in India.

But also, it's just a genuinely fun and interesting place — with an opportunity to work on work on fun and interesting things. I learned a lot there.

Follow @monadfix on Twitter to get notifications about future posts from this series. You can also leave a comment on Reddit.