Measure the wildlife labels
Before you start this master track
Functions and immutable lists. Read type signatures, pattern matching, and guards.
Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.
Predict the result.
Which list is printed?
main :: IO ()main = do let names = ["ox", "heron", "lynx"] let widths = map length names print widthsEach mission is a separate Haskell 2010 program using the standard Prelude. Save one as Main.hs and run with runghc Main.hs. String output uses putStrLn; numeric lists use print.
Review the lesson
Haskell functions transform values without changing the original input. map applies a function to every item of a list, preserving its order. Here length measures each animal name, producing a new list of label widths. The indentation under do groups the small steps that prepare and print the result.