-- D. Sannella. M Fourman, H. Peng and P. Wadler
-- Introduction to Computation: Haskell, Logic and Automata
-- Undergraduate Topics in Computer Science, Springer (2021)
-- ISBN 978-3-030-76907

-- Chapter 21 : Data Abstraction

-- Defining intersection for an abstract data type of sets

module AbstractSetAsList_MyModule' where
  import AbstractSetAsList
  
  intersect :: Set -> Set -> Set
  s `intersect` t
    | isEmpty s = empty
    | choice `element` t
                = singleton choice `union` (rest `intersect`  t)
    | otherwise = rest `intersect`  t
    where choice = select s
          rest = delete choice s
