Minimal static boilerplate for Ellie

If you use Ellie for quick non-interactive experiments like I do when playing with different language features or trying out API ideas, you probably find yourself either deleting the default code that a new Ellie is populated with, or somewhat awkwardly adding bits to it.

Update: Bill St. Clair showed me a much shorter boilerlate:

module Main exposing (main)

import Html exposing (text)

main =
    text "hello"

That’s it! main doesn’t have to be a Program value - it can be an Html value too.

Here is a link to the Ellie with this code:

Original boilerplate below.

I kept doing that for a while, and finally I decided to document a minimal boilerplate for static content:

module Main exposing (main)

import Browser
import Html exposing (text)

main : Program () () Never
main =
    Browser.sandbox { init = (), view = \_ -> text makeStr, update = \_ _ -> () }

makeStr : String
makeStr =
    Debug.toString [ 1 ]

Since it’s only a few lines, it’s easy to add your own code. To produce output, just modify the makeStr value.

And here is a link to an actual Ellie with this code:

Comments or questions? I’m @alexkorban on Twitter.

Looking for the nuts-and-bolts guide to creating non-trivial real world apps in Elm?

My book, Practical Elm for a Busy Developer, skips the basics and gets right into explaining how to do practical stuff. Things like building out the UI, communicating with servers, parsing JSON, structuring the application as it grows, testing, and so on. No handholding — the focus is on giving you more substance.

It’s up to date with Elm 0.19.

Pop in your email to get a sample chapter.

(You will also get notifications of new posts along with other mailing list only freebies.)

Book cover