Haskell Backend Demo
Try a compact MicroHs WebAssembly runtime that runs a practical Haskell subset in the browser, without requiring the full Glasgow Haskell Compiler toolchain.
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.
- Run the program and confirm that it prints
[2,4,6]. - 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.
module Main where
doubleScores :: [Int] -> [Int]
doubleScores scores = scores
main :: IO ()
main = print (doubleScores [1, 2, 3])
Solution
module Main where
doubleScores :: [Int] -> [Int]
doubleScores scores = map (* 2) scores
main :: IO ()
main = print (doubleScores [1, 2, 3])
map (* 2) scores creates a new list by applying multiplication by two to every score. doubleScores stays pure: it returns a value without printing or mutating anything. The separate main action is responsible for displaying that value.