Skip to content

Instantly share code, notes, and snippets.

View pkamenarsky's full-sized avatar
💭
I may be slow to respond.

Philip Kamenarsky pkamenarsky

💭
I may be slow to respond.
View GitHub Profile
module Main (main) where
{-| The main module
@docs main
-}
import Html exposing (Html, div, button, text)
import Html.Attributes as Html exposing (style)
import Html.Events exposing (onClick)
import StartApp as StartApp
/* Thunk
Creates a thunk representing the given closure.
Since we want automatic memoization of as many expressions as possible, we
use a JS object as a sort of tagged pointer, where the member x denotes the
object actually pointed to. If a "pointer" points to a thunk, it has a
member 't' which is set to true; if it points to a value, be it a function,
a value of an algebraic type of a primitive value, it has no member 't'.
When a thunk is evaluated, by reading the member 'x' of the "pointer," the
closure is evaluated and the getter removed, to be replaced with the value
(reduce (fn [a [k v]]
(if (a k)
(update-in a [k] conj v)
(assoc a k [v])))
{}
...)