I'm writing a function that uses one list as an occurrence. The function then takes this list and removes all occurrences of it from another list.
For example:
[1,2,3] should be removed from [3,2,1,2,3,1,2,3] giving us [3,2]
[1,2,3] should not be removed in the way that I would get an empty list []
So far I've got it to remove one of all the occurrences, but it won't remove any others.
Here is my function:
fun deleteAll l1 [] = []
| deleteAll l1 (hd::tl) =
if starts l1 (hd::tl)
then (deleteAll l1 tl; delete l1 (hd::tl))
else [hd]@deleteAll l1 tl;
Here are the other functons that are used within it:
fun starts [] l2 = true
| starts l [] = false
| starts (h1::t1) (h2::t2) = (h1=h2) andalso (starts t1 t2);
fun delete l1 [] = []
| delete l1 (hd::tl) =
if starts l1 (hd::tl)
then List.drop(hd::tl, length l1)
else [hd]@delete l1 tl;