Go backward to Generic Element Types
Go up to Top
Go forward to Another Example

Hiding the Representation

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

type GenericStackWRT[Item][Stack] =
  {emptyStack = nil[Item],
   push = fun(a: Item, s: List[Item]) cons[Item](a,s),
   pop = fun(s: List[Item]) tl[Item](s)
   top = fun(s: List[Item]) hd[Item](s)}

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

useStack(listStackPackage)


Wolfgang.Schreiner@risc.uni-linz.ac.at
Id: understand.tex,v 1.1 1996/06/12 09:38:21 schreine Exp schreine

Prev Up Next