This will give your desired output.
fun map_one [] (old,x) = x
| map_one ((p,f)::fs) (old,x) =
if p old
then map_one fs (old,(f x))
else map_one fs (old,x)
fun map_many _ [] = []
| map_many fs (x::xs) = map_one fs (x,x) :: map_many fs xs
Note that map_one
uses a tuple int*int
to keep track of the old value (which you use in your predicates), and the generated value.
Your code was only using each pair of functions once, and each number once. You were always putting ys
and xs
into the recursive function, running them down at the same rate, rather than running the first one down, moving down once on the second, then running the first one down again. You were performing max(length(ys),length(xs))
operations, when you wanted to be doing length(ys)*length(xs)
.