It is possible to define local variables inside a function to
- reduce code repetition
- give name to subexpressions
- reduce the amount of passed arguments.
The construct for this is
let ... in ....
bigNumbers = let allNumbers = [1..100] isBig number = number > 95 in List.filter isBig allNumbers > bigNumbers [96,97,98,99,100] : List number > allNumbers -- error, doesn't know what allNumbers is!
The order of definitions in the first part of
let doesn’t matter!
outOfOrder = let x = y + 1 -- the compiler can handle this y = 100 in x + y > outOfOrder 201 : number
if you want to reproduce, please indicate the source:
elm – Functions and Partial Application – Local variables - CodeDay