`map` applies one function independently to every element of a list and returns a new list of the results, in the same order. Supply the element transformation first and the list second. It is useful whenever the same change must be made across every character, number, or other list element. section 2.5.3 section 2.6
Instead of writing explicit recursion for a routine transformation, define the operation for one element and let `map` apply it throughout the list. This keeps the operation focused: character rotation stays a character-level function, while `map` handles the whole `String`. section 2.5.3 section 4.3.3
Rotate every character in a message
A Caesar cipher rotates one `Char` at a time with `rotChar`. Mapping that function over a message produces the transformed `String`; `rot13` then specializes the offset to 13. `caesar n message = map (\ch -> rotChar n ch) message` This separation makes the per-character rule reusable while the list traversal remains concise. section 2.5.3
Keep input and transformation separate
A program can read a line with an IO action, then use pure code to transform every character before printing it: `putStrLn (map toUpper line)` Here `map toUpper` performs the uppercase conversion without side effects; input and output remain at the program boundary. section 3.2.1
Common patterns include:
- Transform a `String` character by character, such as converting it to uppercase or rotating letters for a cipher. section 2.5.3 section 3.2.1
- Compose transformations over a list, such as mapping `show` and then `length` before taking `maximum`. section 4.3.3
- Choose `zipWith` rather than `map` when a transformation must combine corresponding elements from two lists. section 4.3.3
Listing 2.11 Functions that perform Caesar’s cipher and ROT13
caesar :: Int -> String -> String caesar n message = map (\ch -> rotChar n ch) message #1 rot13 :: String -> String rot13 message = caesar 13 message #2
Inspect a complete `map` use in which a character transformation becomes a reusable Caesar cipher over an entire message. section 2.5.3







