|
class version | module version | |
The type of stacks | 'astack |
'a Astack.t |
Create a stack | newstack |
Astack.created() |
Push x on s | s#push x |
Astack.push x s |
Pop from s | s#pop |
Astack.pop s |
top
to explore the top of the stack without popping
it. Both implementations, described in Figure 5.1, are
straightforward: the class approach uses inheritance while the module
approach uses the include
construct. (The effect of
includeStack
is to rebind all components of the
Stack
structure in the substructure.)
|
pop
would automatically benefit to the
implementation of top
(ie. the method
top
would call the new definition of pop
). This mechanism does
not have any counterpart in OCaml modules.