Component values, each managing its own state, rendering its own UI, and communicating with other components through a typed hierarchy.
The three pillars
Model
Any Haskell type with an
Eq instance. Holds all state for a component. Starts from an initial value and evolves over time in response to actions.View
A pure function
model -> View model action. Produces a virtual DOM tree that miso diffs against the real DOM to compute the minimum set of changes.Update
A function
action -> Effect parent model action. Handles every event, mutates the model using monadic state operations, and schedules any required IO.The MVU cycle
Each frame, miso runs the same loop:- The
viewfunction converts the current model into aViewtree. - miso diffs the new virtual DOM against the previous one and patches the real DOM.
- Browser events are captured by miso’s event delegator and decoded into Haskell
actionvalues. updatereceives the action, modifies the model, and optionally schedules IO.- The changed model triggers a new
viewpass.
Component — the core building block
The central type in miso is Component:
App is just a Component whose parent is ROOT — a phantom type that signals there is no parent:
component (or its synonym vcomp) smart constructor to create a Component with sensible defaults:
Virtual DOM and event delegation
miso maintains a virtual DOM — a lightweight Haskell representation of the real DOM:view, diffs the resulting tree against the previous one, and applies the minimal patch to the real DOM.
Event listeners are not attached individually to DOM elements. Instead, miso attaches a single listener to a top-level element (typically <body>) and routes events through the virtual DOM tree to the correct Haskell handler. Both the capture and bubble phases are supported.
Compilation targets
miso supports three backends. The same Haskell source code runs on all of them:WebAssembly (WASM)
Compiled with GHC’s WASM backend. Supports hot-reload via WASM browser mode and
ghciwatch.JavaScript (JS)
Compiled with GHC’s JavaScript backend (
arch(javascript)). Targets browsers via Emscripten.Vanilla GHC
Runs on standard GHC for server-side rendering (SSR), prerendering, and testing.
MisoString type adapts automatically: it is JSString on JS/WASM backends and Data.Text on vanilla GHC.
Running an application
startApp is the right choice for most client-side applications. miso and prerender are used when the server has already delivered HTML and the client needs to attach event handlers without a full repaint.