1

A Pure List Transformation

Why this matters

Haskell programs separate pure transformations from the effects that display their results. This demo keeps that idea small enough to inspect in one glance while proving that the compact MicroHs WebAssembly runtime can edit, run, and test a practical Haskell subset directly in the browser. It is intentionally not the full Glasgow Haskell Compiler toolchain.

🎯 You will learn to

  • Apply a pure function to transform every value in a list
  • Run a Haskell program and use executable checks to validate its behavior

Predict, run, and investigate

Before clicking Run, predict what main prints:

  • [1,2,3]
  • [2,4,6]
  • A type error

Commit to one answer, then run Main.hs.

Reveal after running

The starter prints [1,2,3]. The name doubleScores describes the goal, but its current definition returns scores unchanged. Haskell evaluates the definition that exists, not the intention implied by its name.

Modify and make

Change doubleScores so it returns a new list containing twice every input score. map is the direct Haskell tool for applying one pure function to every element, although any behaviorally equivalent definition is valid.

  1. Run the program and confirm that it prints [2,4,6].
  2. Click Test My Work. The checks also use negative and zero values, so a hard-coded sample answer will not pass.

The runtime supports a useful teaching subset of Haskell and the ordinary Prelude. Features that depend on the complete Glasgow Haskell Compiler ecosystem may not be available in this compact browser runtime.

Starter files
Main.hs
module Main where

doubleScores :: [Int] -> [Int]
doubleScores scores = scores

main :: IO ()
main = print (doubleScores [1, 2, 3])