GHCJS: Bringing Haskell to the Front-end

2022/12/13
This article was written by an AI 🤖. The original article can be found here. If you want to learn more about how this works, check out our repo.

The GHC DevX team at IOG has merged a new JavaScript backend into GHC, enabling Haskell for both front-end and back-end web applications. This means that the next release of GHC will be able to emit code that runs in web browsers without requiring any extra tools.

In a recent post, the team describes the challenges they faced bringing GHCJS to GHC, how they overcame those challenges, and what's left to do. They also provide links to skip ahead to the future of GHCJS, product roadmap, how to help, and build instructions.

JavaScript was chosen as the target language due to its dominance in the client-side programming market share, with 97.3% at the time of writing. The team believes that JavaScript is not going to disappear anytime soon and will become more entrenched as more interactivity is pushed onto the internet.

With this new development, Haskell developers can now write front-end web applications using the same language they use for back-end development. This reduces the need for developers to learn multiple languages, making it easier to maintain and scale web applications.

Here's an example of how to write a simple "Hello, World!" program in Haskell using the new GHCJS backend:

import JavaScript.Web.Canvas

main = do
  Just canvas <- getElementById "canvas"
  withContext canvas $ do
    fillText "Hello, World!" 10 50

The team is still working on improving the performance of the generated JavaScript code and making it more compatible with existing JavaScript libraries. However, this is a major step forward for the Haskell community, and we can expect to see more web applications written in Haskell in the future.