Purview

A simple, fun way to build websites with Haskell.

Composable

A different way of building HTML, where attributes flow down to concrete HTML.


submitStyle = [style|
  color: blue;
  font-size: 36px;
|]

submitAttr =
  Attribute "type" "submit"

submitButton
  = submitAttr
  $ submitStyle
  $ button [ text "Submit" ]
    

Familiar

Handling events follows the usual state -> event -> new state, with a little extra to send new events to itself or a parent.


data Counter =
  Increment | Decrement
  deriving Show

countHandler = handler' [] 0 reducer
  where
    reducer state Increment =
      (state + 1, [])
    reducer state Decrement =
      (state - 1, [])

view count = div
  [ h1 [ text (show count) ]
  , onClick Increment $ button [ text "+" ]
  , onClick Decrement $ button [ text "-" ]
  ]

component = countHandler view

Effectful

Designed to work nicely with effects. Set an interpreter which applies to all event handlers.


interpreter' :: Eff '[Time, IOE] a -> IO a
interpreter' = runEff . runTimeIO

configuration = defaultConfiguration
  { interpreter = interpreter' }

main = serve
  configuration
  component

Practical

  • Easy, non-blocking IO. Each handler is run in a green thread.
  • Basic hot reloading.
  • Call Javascript by returning a special Browser event from handlers.
  • Receive events from Javascript by placing a Receiver beneath a handler.