Build Haskell stuff in your browser

tl;dr

You can write and execute non-trivial Haskell on repl.it (I’m not affiliated with them).

That environment secretly includes not just base, but couple of other useful libraries.

You can write interactive command-line programs and have them automagically served up on the web.1

What’s an online REPL?

In case you don’t already know, there has been a surge of online programming environments in recent years, most notably interactive notebooks and REPLs. This stuff is really popular the webdev and data science communities2.

The idea is that you can type in some commands, have them executed by whatever interpreter, write code in files/modules, build interactive programs, create visualizations, entire websites, and so on.

That last one is what this post is about. Repl.it is great for many reasons, not least because it started providing a Haskell environment two years ago.

sidenote: repl.it has this feature where multiple people can join the same editor and all edit at the same time, which is insanely cool. Get some friends and click the “multiplayer” button.

The libraries nobody told you about

Unfortunately it’s not clear which packages apart from base are built in. Random guessing quickly shows that at least containers and text are available, but I couldn’t find a complete list anywhere. Of course we won’t let that stop us. After a bit of fiddling and exploring:

FUN. I don’t know about you, but at this point I get pretty excited, since this means that we can write a lot more serious stuff than I had initially realized.

For example, we can write entire interactive command-line programs that repl.it will automatically serve up at https://[replname].[username].repl.run. Here you can play with an example I simply copy-pasted from the haskeline documentation.

If you’re not familiar with the libraries above, here’s an (incomplete) overview:

The great containers lets you use Set, Map, Graph, and Tree. The first two are especially nice if you’re used to dictionaries and sets from other languages.

The low-level array gives you a structure that is faster than list for accessing elements at an arbitrary index.

parsec is your entry ticket into the world of parser-combinators INDUSTRIAL-STRENGTH PARSER COMBINATORS.

text and bytestring replace String as the proper way to do either user-readable strings or binary data respectively.

template-haskell is how you write Haskell that writes Haskell creates splices, which is metaprogramming and probably nice.

filepath and directory let you interact with the file system, which repl.it totally lets you do!

That’s it for now, figure out the other libraries yourself. It would obviously be great to have more. For example to have wreq to make network requests, or some graphics package to create images or draw on the DOM.

With enough interest repl.it might be persuaded to include more packages. Before discovering all this, I messaged them on their twitter to ask if they could update GHC from 8.0.x to 8.6.3 in the coming year, and they literally did it within an afternoon. Amazing.

Your main function will be run in a little pseudo-terminal, so all your dumb adorable little putStrLn and getLine will print text or wait for user input. You can’t pass arguments or flags to your program tough, since you don’t control stdin. It has to be interactive with something like getLine.
[return]

I was skeptical of online programming environments at first, since the idea sounds a bit gimmicky. I changed my mind8 after seeing how many children build really impressive things in them, and how joyful it feels to use one for quick demos and experiments. It’s really easy to send somebody a code snippet that just executes, zero friction. Beginners can still install stack or cabal afterwards, no rush.
[return]

We also have our very own Haskell Kernel currently maintained by total champion Vaibhav Sagar. It’s all there, but more help is needed to remove some frictions for beginners, like a noob-friendly install experience and more cool tutorials. EDIT: I’m being informed on reddit that you can actually use IHaskell online.
[return]