previous up next
Go backward to Generic Element Types
Go up to Top
Go forward to Another Example
RISC-Linz logo

Hiding the Representation

type GenericStack =
   forall Item. exists Stack. GenericStackWRT[Item][Stack]

type GenericStackWRT[Item][Stack] =
  {emptyStack: List[Item],
   push: (Item x List[Item]) -> List[Item]
   pop: List[Item] x List[Item],
   top: List[Item] -> Item}

value listStackPackage: GenericStack =
      pack[Stack = List[Item]
         in GenericStackWRT[Item][Stack]]
value useStack =
   fun(stackPackage: GenericStack)
      open stackPackage[Int] as p[stackRep]
      in, p.emptystack))


Author: Wolfgang Schreiner
Last Modification: May 27, 1998

previous up next