Behavioral subtypes

stack <= bag


  • bag -- put, get
  • stack -- push, pop, settop

Representation

  • bag -- << elems, bound >> \zline{multiset}
  • stack -- << items, limit >> \zline{sequence}

Behavior -- put/push


  put(i):
    require   size( b.elems ) < b.bound
    promise   b' = << b. elems \uplus { i }, b.bound >>
  
  push(i):
    require   length( s.items ) < s.limit
    promise   s' = << s.items \. i, s.limit >>
  

slide: Behavioral subtypes -- example