Please Ignore

For those who can’t read titles:

I’ve been interested in literate programming for a while. I’m interested in the relationship between artificial languages and in how we can program more transparently. Literate programming sites at the margins of that.

I’ve also been playing around with PureScript some. It’s Haskell, redesigned to remove some warts, that transpiles to JavaScript. So far I haven’t used it very much, but I’d like to work with it more.

So creating the ability to create literate PureScript posts on this blog has been on my todo list for a while. Now that I’ve actually started posting again, I thought I’d get this going. For those who are interested and maybe morbidly curious, the changes are in this diff. There are a few moving parts, but mostly I just hand things over to pulp as much as I can.

Since this is a literate post, there are some formailities to get started:

module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Data.Traversable (traverse)
import DOM (DOM)
import DOM.HTML (window)
import DOM.HTML.Types (htmlDocumentToDocument, htmlDocumentToParentNode)
import DOM.HTML.Window (document)
import DOM.Node.Document (createTextNode)
import DOM.Node.Node (appendChild)
import DOM.Node.NodeList (item)
import DOM.Node.ParentNode (querySelectorAll, QuerySelector)
import DOM.Node.Types (textToNode)
import Data.Newtype (wrap)

(If this all seems a little verbose, I’m using a very low-level interface here. For anything more complicated, you’d want to use a higher-level library.)

There are still some things to do on this:

  • Syntax color highlighting;
  • The code doesn’t work well with the margins;
  • The code doesn’t work well with the scalable font sizing.
main :: forall e. Eff (console :: CONSOLE, dom :: DOM | e) Unit
main = do
    doc      <-  window >>= document
    greeting <-  textToNode
             <$> createTextNode "Hello sailor!"
             (   htmlDocumentToDocument doc)
    _ <- querySelectorAll (wrap "#please-ignore .please-ignore")
        (   htmlDocumentToParentNode doc)
        >>= item 0
        >>= traverse (appendChild greeting)
    log "Hello sailor!"

As an added bonus, the scaffolded project created by pulp has a gratuitous Zork reference. How could I resist?