map / sum / [1..n]
Transformation and aggregation (instead of loops).
Syntax
map f xs // sum xs // [1..n]
Description
There are no loops in Haskell. map transforms each element, sum adds them up. [1..n] is a range (inclusive of n). IO is applied to each element with mapM_.
Example
Loading editor…
Expected output
[1,4,9] 5050
When to use?
List processing: transforming, summing, filtering.