fun reduce(f,a,nil) = a |reduce(f,a, (x::xs)) = f(x,reduce(f,a,xs));
fun altnfold(f,g,0,x) = x + 0.0 |altnfold(f,g,n,x) = f(g(altnfold(f,g,n-1,x)));
map(inc, [2,4,6]);[3,5,7]
nfold(inc,5) 4;9
filter(even, map(inc, [1,2,3,4]));[2,4]
map(nfold(inc,2), [1,2,3,4]);[3,4,5,6]
fun A x = false;Defines the empty set.
fun B (f,g) = fn x => f(x) orelse g(x);Defines the union of sets f and g
fun B (f,g) = fn x => f(x) andalso g(x);Defines the intersection of sets f and g
fun D (x,f) = fn y => (x=y) orelse f(y);Defines the union of {x} and f
fun E (f,g) = fn y => f(y) andalso (not (g(y)));Defines the difference (subtraction) of sets f-g
local fun f (dbIntConst(x),D) = true |f (## k, D) = (k<=D) |f (dbOp(e1,_,e2),D) = f(e1,D) andalso f(e2,D) |f (dbLet(e1,e2),D) = f(e1,D) andalso f(e2,D+1) in fun closed e = f(e, 0) end;For case two, either less than or less than or equal to was accepted. The difference comes from whether deBruijn indices start at 0 or 1.