Public
Edited
Dec 14, 2023
Fork of Purescript
1 fork
1 star
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
html = unsafe_html`${module.render}`
Insert cell
Insert cell
module.main()
Insert cell
// mdPlus`## Todo

// Reach out on the [purescript discord](https://purescript.org/chat) if you have ideas or want to help!

// - [x] Add syntax highlighting (partially done using the \`haskell\` grammar and https://observablehq.com/@cmudig/editor).
// - [x] Improve warnings and errors rendering
// - [x] Added a version of the original try purescript
// - [x] Make this notebook into a nicely importable notebook. https://observablehq.com/@jmatsushita/purescript
// - [ ] How would multiple modules work?
// - [ ] Display spinner while compiling`
Insert cell
Insert cell
Insert cell
ps = await Purescript(source)
Insert cell
Insert cell
errors = ps.errors
Insert cell
warnings = ps.warnings
Insert cell
import { Purescript } from '@jmatsushita/purescript'
Insert cell
Purescript
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {localStorageView} from '@tomlarkworthy/local-storage-view'
Insert cell
Insert cell
Insert cell
Insert cell
viewof source = localStorageView("source", { 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
// import {mdPlus} from "@tmcw/bonus-markdown-flavor"
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