99 questions/Solutions/22
< 99 questions | Solutions
Jump to navigation
Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Create a list containing all integers within a given range.
range x y = [x..y]
or
range = enumFromTo
or
range x y = take (y-x+1) $ iterate (+1) x
or
range i k
| i <= k = i : range (i + 1) k
| i > k = []
Since there's already syntactic sugar for ranges, there's usually no reason to define a function like 'range' in Haskell. In fact, the syntactic sugar is implemented using the enumFromTo function, which is exactly what 'range' should be.