Public
Edited
May 25, 2024
2 forks
Importers
1 star
Topic Diffusion modeling
Purescript
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
module.val
Insert cell
Insert cell
module.greet("me")
Insert cell
Insert cell
module.main()
Insert cell
Insert cell
Insert cell
Insert cell
ps = await Purescript(source)
Insert cell
// module = ps.module
module = (await Purescript(source)).module
Insert cell
errors = ps.errors
Insert cell
warnings = ps.warnings
Insert cell
renderCompilationStatus = (source, warnings, errors) => {
const renderedWarnings = warnings && warnings.length >0 ?
htl.html`<h3>Compiler warnings</h3><table style="max-width: none;"><thead>
<tr>${toColumns(warnings).map(col => htl.html`<th>${col}</th>`)}</tr>
</thead>
<tbody>
${toTable(warnings, source).map(row => htl.html`<tr>
${Object.values(row).map(cell => htl.html`<td><pre style="text-wrap: balance;">${cell}</pre></td>`)}
</tr>`)}
</tbody>
</table>
` : htl.html`<code>No warnings</code><br>`

const renderedErrors = errors ? htl.html`<h3>Compiler errors</h3><table style="max-width: none;">
<thead>
<tr>
${toColumns(errors).map(col => htl.html`<th>${col}</th>`)}
</tr>
</thead>
<tbody>
${toTable(errors, source).map(row => htl.html`<tr>
${Object.values(row).map(cell => htl.html`<td><pre style="text-wrap: balance;">${cell}</pre></td>`)}
</tr>`)}
</tbody>
</table>
` : htl.html`<code>No errors</code>`
return htl.html`${renderedWarnings}${renderedErrors}`
}
Insert cell
import { Purescript } from '@jmatsushita/purescript'
Insert cell
Purescript
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
PurescriptEditor = async (doc = '', extensions = []) => {
const {StreamLanguage} = await import(`https://jspm.dev/@codemirror/language@6.9.3`)
const { haskell } = await import(`https://jspm.dev/@codemirror/legacy-modes/mode/haskell`);
return CodeMirror(doc, {
extensions: [myDefaultTheme, StreamLanguage.define(haskell), ...extensions]
});
}
Insert cell
Insert cell
import {localStorageView} from '@tomlarkworthy/local-storage-view'
Insert cell
Insert cell
Insert cell
Insert cell
viewof source = localStorageView("sourceDiffTopic", { defaultValue: example })
Insert cell
// creating a fake source to subscribe from, together with a bound localStorageView didn't work.
// Uncaught TypeError: e.closest is not a function
// at inputs.min.js:40:1444
// viewof source = Inputs.input()
// viewof sourceStorage = localStorageView("sourceStorage")
// Inputs.bind(viewof source, viewof sourceStorage)
// See reproducer here https://observablehq.com/d/f7e7508476855e8b#cell-264
Insert cell
Inputs.bind(viewof editor, viewof source)
Insert cell
// Note you need to get these the right way round to have the page load work correctly
// Inputs.bind(viewof source, viewof sourceStorage)
Insert cell
// set helper
function set(input, value) {
input.value = value;
input.dispatchEvent(new Event("input", {bubbles: true}));
}
Insert cell
Insert cell
toTable = (array, source) => array ? array.map(row => objectFilter(objectMap(row, toReadableRow(source)), hideColumns)) : []
Insert cell
hideColumns = k => k !== "allSpans" && k !== "moduleName" && k !== "filename" && k !== "errorLink"
Insert cell
toColumns = array => array && array[0] ? Object.keys(array[0]).filter(hideColumns) : []
Insert cell
toReadableRow = source => (v,k) => {
switch(k) {
case "allSpans":
return JSON.stringify(v)

case "position":
// console.log(source.split("\n"))
// console.log(source.split("\n").slice(v.startLine - 1, v.endLine))
return source.split("\n").slice(v.startLine - 1, v.endLine).join("\n")
default:
return v;
}
}
Insert cell
toTable(warnings, source)
Insert cell
toColumns(warnings)
Insert cell
warnings
Insert cell
errors.contents
Insert cell
toColumns(errors.contents)
Insert cell
toTable(errors.contents, source)
Insert cell
Insert cell
Insert cell
Insert cell
function unsafe_html() {
const span = document.createElement("span");
span.innerHTML = String.raw.apply(this, arguments);
return span;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more