Main_Page/Snack Code/List Recursion/Difference of two lists

Difference of two lists: xs \\ ys is the list xs with each element of ys removed from xs, if its present in ys.


module Sublist where

(\\) xs [] = xs
(\\) [] xs = []
(\\) ls (y:ys) = (remove ls y) \\ ys
    remove [] y = []
    remove (x:xs) y
           | x == y = remove xs y
           | otherwise = x : remove xs y

test = [1,2,3,4,5] \\ [2,4]
*Sublist> test


Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.