(* * consAllk needs to be defined for these to work * I put this in a separate file, but you can * just copy in your implementation and remove * the line below *) use "consAllk.sml"; fun appendAll [] = [] | appendAll (x::xs) = x @ (appendAll xs); fun infiltrate x [] = [[x]] | infiltrate x (y::ys) = (x::y::ys) :: (consAllk y (infiltrate x ys)); fun perms [] = [[]] | perms (x::xs) = appendAll (map (infiltrate x) (perms xs));