A categorical programming language
Revision | 140ee01ceba8e0b4ba86adf7f88b9e4fc9719c2f (tree) |
---|---|
Zeit | 2022-10-23 00:23:18 |
Autor | Corbin <cds@corb...> |
Commiter | Corbin |
Don't render empty trails.
Saves a bit of screen space.
@@ -98,11 +98,12 @@ foreign import intSub :: Int -> Int -> Int | ||
98 | 98 | |
99 | 99 | pr :: forall t. (Unit -> Tramp t) -> (t -> Tramp t) -> Int -> Tramp t |
100 | 100 | pr x _ 0 = x Unit |
101 | -pr x f n = bind f (pr x f (intSub n 1)) | |
101 | +pr x f n = bind f (cont (\_ -> pr x f (intSub n 1))) | |
102 | 102 | |
103 | 103 | foreign import arrayHead :: forall t. Array t -> t |
104 | 104 | foreign import arrayTail :: forall t. Array t -> Array t |
105 | 105 | |
106 | 106 | fold :: forall s t. (Unit -> Tramp t) -> (Pair t s -> Tramp t) -> Array s -> Tramp t |
107 | 107 | fold x _ [] = x Unit |
108 | -fold x f c = bind (\t -> f (Pair t (arrayHead c))) (fold x f (arrayTail c)) | |
108 | +fold x f c = bind (\t -> f (Pair t (arrayHead c))) | |
109 | + (cont (\_ -> (fold x f (arrayTail c)))) |
@@ -171,13 +171,15 @@ function drawFrame(canvas, sample, getChannels) { | ||
171 | 171 | function tileForIndex(extractor, index, title, trail) { |
172 | 172 | const div = document.createElement("div"); |
173 | 173 | div.setAttribute("class", "tile"); |
174 | - div.innerHTML = ` | |
175 | - <h3>${title}</h3> | |
176 | - <details> | |
177 | - <summary>Trail</summary> | |
178 | - <p>${trail}</p> | |
179 | - </details> | |
180 | - `; | |
174 | + div.innerHTML = `<h3>${title}</h3>`; | |
175 | + if (trail) { | |
176 | + div.innerHTML += ` | |
177 | + <details> | |
178 | + <summary>Trail</summary> | |
179 | + <p>${trail}</p> | |
180 | + </details> | |
181 | + `; | |
182 | + } | |
181 | 183 | const typeInfo = document.createElement("p"); |
182 | 184 | typeInfo.innerHTML = "Loading type information..."; |
183 | 185 | div.appendChild(typeInfo); |
@@ -253,7 +255,7 @@ function tileForIndex(extractor, index, title, trail) { | ||
253 | 255 | function fetchDip(extractor, dip) { |
254 | 256 | const url = "/dip/" + encodeURIComponent(dip); |
255 | 257 | return fetchJSON(url).then(({expr, trail}) => { |
256 | - return tileForIndex(extractor, expr, dip, trail); | |
258 | + return tileForIndex(extractor, expr, dip, trail.trim()); | |
257 | 259 | }); |
258 | 260 | } |
259 | 261 |
@@ -271,7 +273,7 @@ window.addEventListener("load", (_) => { | ||
271 | 273 | document.getElementById("dissolve-form").addEventListener("submit", (e) => { |
272 | 274 | console.log("making dissolve request"); |
273 | 275 | fetchJSON("/dissolve", { method: "POST", body: dissolveBox.value }).then(({expr, trail}) => { |
274 | - const div = tileForIndex(extractor, expr, "Anonymous expression", trail); | |
276 | + const div = tileForIndex(extractor, expr, "Anonymous expression", trail.trim()); | |
275 | 277 | document.body.appendChild(div); |
276 | 278 | }); |
277 | 279 | e.preventDefault(); |