Learn HalogenGHC loads in the background

Playground

Write a Lesson module that exports component, then press Compile to run it here. Choose library layers below to make their packages available. Your code is compiled in your browser and is not sent to a server.

Layers

Loading the list of available libraries…

Your browser saves your code, selected layers and compiler arguments for your next visit when storage is available. Reset restores the example code.

Lesson.hs
{-# LANGUAGE OverloadedStrings #-}

-- Export component to display it in the result area. Its input is ():
-- component :: forall q o m. (MonadIO m) => H.Component q () o m
module Lesson (component) where

import Control.Monad.IO.Class (MonadIO)
import Control.Monad.State (modify)
import Data.Text qualified as T
import Halogen qualified as H
import Halogen.HTML qualified as HH
import Halogen.HTML.Events qualified as HE

data Action = Clicked

component :: forall q o m. (MonadIO m) => H.Component q () o m
component =
  H.component initialState render [H.onAction handleAction]
  where
    initialState _ = pure (0 :: Int)
    render clicks =
      HH.div_
        [ HH.button [HE.onClick (\_ -> Clicked)] [HH.text "Click me"]
        , HH.p_ [HH.text ("Clicks: " <> T.pack (show clicks))]
        ]
    handleAction action = case action of
      Clicked -> modify (+ 1)

The compiler loads once the page has started.

Your component will appear here after compilation.