Erik Simmler

Internaut, software developer and irregular rambler

Elm range syntax

Update: Elm’s list range syntax has been removed as of version 0.18. The replacement is List.range 1 2, which is if nothing else more searchable.

I recently stumbled around for more than a few moments searching for a canonical way to generate a range of numbers in Elm. I finally found a working example by searching for “haskell range syntax”.

> [1..2]
[1,2] : List number

Elm doesn’t appear to support the more advanced variants such as [1,3..20], but this definitely covers 95% of my use cases.

This is actually documented under the Lists section of the syntax docs, but there aren’t any useful words for a search to match on. Hopefully this post will save a few minutes for a few people.