I’m looking for an SML function that takes a nonnegative integer and returns a list of all integers from 0 up to but not including the given value, analogous to range() in Python. Yes, I can (and have) written my own, but I’d prefer something built in that I don’t need to copy and paste into every project I want to use it in. Any ideas? Thanks in advance!
% Python code
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
(* SML code: my implementation; I'd prefer a built-in version *)
fun range x =
let fun helper current stop =
if current = stop
then nil
else current :: (helper (current + 1) stop)
in helper 0 x
end;
(* my code when run *)
- range 10;
val it = [0,1,2,3,4,5,6,7,8,9] : int list
This is maybe not as readable, but…