So I’m glad that there’s now an official JS GHC backend, but after getting lambasted on not knowing the difference between compilers and transpilers on IRC, I do have to vent my pique here.
I confess that, through my ignorance, I’m at fault, but the JS GHC backend is not human readable and comes with the full Haskell RTS. This is a big problem because, well, from what I’ve seen of certain JSers and Haskellers, JS is potentially a new Hascalator (wherein Scala users keep getting fed up with the limitations of Scala and jump ship to Haskell). It seems many advanced Javascript developers are into functional programming, attempt to import Haskell-style features into JS (see the notorious FantasyLand incident), and some have even gone so far as to say “to get JS, you should learn Haskell first”. And while you might know of certain prominent Haskellers who were working in Javascript before they got their Haskell jobs, I’m shocked by what seems to be an abnormal number of Javascript developers who decided to learn Haskell.
The fact that the JS GHC backend is a compiler, not a transpiler, is disappointing in that we can’t cater more to the needs of Haskell’s JS fans. Human-readable, or at least JS-recoverable, transpiled Haskell code has the advantage that if a shop already working in functional Javascript wants to do Haskell as an experiment, in case of failure, they can always transpile back into JS and recover their efforts via Node or whatnot, encouraging at least experimental Haskell use. Likewise, the ability to transpile out, means that for Haskellers, if our Haskell code is impenetrable to people unused to expression-oriented languages or the various abstractions Haskell uses, we can always dump into an extremely-commonly-used language to make our code useful.
Of course, it’s unreasonable to expect the JS GHC backend to be anything else; Fay already exists, but is intended to be a subset, Purescript already exists, but is strict, Elm is already there, and lacks typeclasses, or, JS GHC differentiates itself by attempting to translate as much of Haskell as possible (TH isn’t expected on the first pass).
But are there any serious efforts to either fully transpile Haskell into JS, or alternately at least present a human-readable Haskell code in JS? Performance is not the emphasis, the emphasis is being able to show our <$>, >>=, $, infested, IO-monaded code to passerby or otherwise present recoverable code after a failed project.
It’d also help with Javascript learners of Haskell; i.e, if they can’t get their project working, well, they already know the “assembly of the web” (not to be confused with WASM, of course), they can compile, then hack away at the resulting code, and still have a usable project.
Come to think of it, I don’t see anyone else noticing the JS-to-HS train, am I misinterpreting the evidence? If not, are there any efforts to help these folks along and hopefully move Node / JS shops into Haskell or Elm-Haskell shops?