Add primop genList

This can be used to implement functions like ‘imap’ (or for that
matter, ‘map’) without the quadratic complexity incurred by calling
‘++’ repeatedly.
This commit is contained in:
Eelco Dolstra 2015-07-28 17:27:32 +02:00
parent f3dda728a4
commit 50807f3dd5
3 changed files with 41 additions and 3 deletions

View file

@ -54,8 +54,8 @@ rec {
const = x: y: x;
range = first: last:
if builtins.lessThan last first
then []
else [first] ++ range (builtins.add first 1) last;
if first > last
then []
else genList (n: first + n) (last - first + 1);
}