7.6.2 Object Style

We now turn the library stacks into an abstract data structure Stack.ozfModule/. A precompiled version of Stack.ozf is available on-line at Functors/Version.3.2/Stack.ozf

<Stack.oz>=
functor 
import 
   Stack(new fromList get put top  
         isEmpty clear toList push pop)  at 'StackLib.ozf' 
export 
   new      : NewStackObject   
   fromList : ListToStackObject
define 
   fun {NewStackObject}      {ToObject {Stack.new}} end 
   fun {ListToStackObject L} {ToObject {Stack.fromList L}} end 
   fun {ToObject S}
      fun  {Get    } {Stack.get     S  } end 
      proc {Put   X} {Stack.put     S X} end 
      fun  {Top    } {Stack.top     S  } end 
      fun  {IsEmpty} {Stack.isEmpty S  } end 
      proc {Clear  } {Stack.clear   S  } end 
      fun  {ToList } {Stack.toList  S  } end 
      proc {Push  X} {Stack.push    S X} end 
      fun  {Pop    } {Stack.pop     S  } end 
   in 
      unit(
         get     : Get
         put     : Put
         top     : Top
         isEmpty : IsEmpty
         clear   : Clear
         toList  : ToList
         push    : Push
         pop     : Pop)
   end 
end

We can now use stacks by linking a compiled version of the module Stack.ozf from the usual URL.


Denys Duchier, Claire Gardent and Joachim Niehren
Version 1.3.99 (20050412)