1
and n
would normally be handled by an imperative language, C:1
to n
, updating the stored value of the sum
variable on each iteration. In the case of n = 3
:[n .. m]
β which produces a list of numbers from n
to m
, e.g. [1..3] => [1, 2, 3]
sum
β which produces the sum of a listsum
is a predefined function in the Haskell standard library, called Prelude, which is imported by default into all Haskell modules. Libraries are collections of functions written by other people to solve various problems that we can use without having to write them ourselves.=
in Haskell is not the assignment operator as in imperative languages, but the equivalent of the mathematical equal sign.