Skip to content

Haskell Series

This sample shows a compact Haskell note. It lets readers change a numeric sequence and inspect the result that runs from a build-time WASI module in the browser.

  • Reactive Haskell inputs for sequence parameters.
  • Standard-library Haskell code with a lifted import.
  • Text output captured from putStrLn.

The cell computes scaled triangular numbers. Toggle the delta output to compare each term with the previous one.

Haskell + WASI

Explore a Haskell series

Cell actions
Cell inputs
import Data.List (intercalate)

let indexes = [1 .. count]
let values = map (\n -> multiplier * n * (n + 1) `div` 2) indexes
let deltas = zipWith (-) (drop 1 values) values

putStrLn (label ++ ": " ++ intercalate ", " (map show values))
putStrLn ("total = " ++ show (sum values))

if show_deltas
  then putStrLn ("deltas = " ++ intercalate ", " (map show deltas))
  else putStrLn "deltas hidden"

Waiting for the runtime to start.

Haskell cells are intended for deterministic examples that fit the standard library. Use them when a short functional transformation is clearer than a handwritten table of results.

Import the bundled Oxiquill.Output helper to emit JSON values, tables, and existing chart specifications. It uses only GHC’s base package. Build JSON explicitly with JsonValue constructors; Haskell’s show is not a JSON encoder. Numbers must be finite and strings must contain Unicode scalar values.

Haskell + WASI

Structured Haskell output

Cell actions
import qualified Oxiquill.Output as Output

putStrLn "Before structured output"
Output.displayJson (Output.JsonObject
  [("message", Output.JsonString "Unicode: \x65e5\x672c \x1f30d\nquoted: \"value\"")
  ,("ready", Output.JsonBool True)])
Output.displayTable ["Index", "Square"]
  [[Output.JsonInteger n, Output.JsonInteger (n * n)] | n <- [1 .. 4]]
Output.displayChart (Output.JsonObject
  [("kind", Output.JsonString "line")
  ,("series", Output.JsonArray [Output.JsonObject
    [("name", Output.JsonString "Squares")
    ,("points", Output.JsonArray
      [Output.JsonArray [Output.JsonInteger n, Output.JsonInteger (n * n)] | n <- [1 .. 4]])]])])
putStrLn "After structured output"

Run the cell to show its output.

The helper writes versioned, length-prefixed frames to stdout. Ordinary putStrLn text is preserved; use Output.putText when printing the reserved record separator (0x1e) literally. Frames contain one JSON, table, or chart artifact. Malformed frames are reported locally. Text streams retain their separate 1 MiB limits, while structured output uses the shared artifact count and byte budgets.