[Haskell-cafe] Stack ADT?

Sebastian Fischer sebf at informatik.uni-kiel.de
Thu Feb 4 18:29:07 EST 2010


On Feb 4, 2010, at 6:27 PM, michael rice wrote:

> I haven't done much with modules so I'm guessing what you've  
> provided is the guts of StackImpl, to hide the implementation?

Right. In order to make the Stack type abstract, you can hide the  
Stack data (that is, newtype) constructor and only export the Stack  
type constructor and the operations. You can use the following module  
header (I should have provided it in the first place):

     module Data.Stack (Stack, emptyStack, isEmptyStack, push, pop,  
top) where

Making the Stack type abstract has the advantage that you can later  
change the implementation without affecting users of your Stack  
library which can only depend on its interface.

Sebastian

-- 
Underestimating the novelty of the future is a time-honored tradition.
(D.G.)





More information about the Haskell-Cafe mailing list