fun applyList nil _ = nil | applyList (F::Fs) a = F(a)::(applyList Fs a); fun makeFnList F nil = nil | makeFnList F (x::xs) = F(x)::(makeFnList F xs); (* ss1(L,M) tests whether list L is a prefix of list M *) fun ss1(nil, _) = true | ss1(_, nil) = false | ss1(x::xs, y::ys) = (x=y andalso ss1(xs,ys)); (* ss2(L,M) tests whether list L is a sublist of list M *) fun ss2(x, nil) = ss1(x,nil) | ss2(x, y::ys) = ss1(x,y::ys) orelse ss2(x,ys); (* substring converts strings to lists and applies ss2 *) fun substring x y = ss2(explode(x),explode(y)); val f = makeFnList(substring); val [he, she, her, his] = f ["he", "she", "her", "his"]; applyList [he, she, her, his] "hershey";