[Haskell-cafe] Abstract Data Types

Johan Grönqvist johan.gronqvist at gmail.com
Wed Aug 9 05:27:51 EDT 2006


Hi,

I have a question:

Short version: If I want to hide the implementation of a data-type 
"Stack a" from the rest of the program,  do I need to put its definition 
in a separate file?


Long version:

I want to use a stack, and I might implement it as a list, but I want to 
hide the implementation from the rest of the program. This is how I 
understand abstract data type.

In "The Craft of Functional Programming", this seems to be implemented 
by putting each data type into a separate module and only exporting 
parts of the definitions.

In "The Haskell School of Expression", this seems not to be used at all.

In the lecture notes at 
(http://www.dcs.shef.ac.uk/~mps/courses/com2020/adts.pdf), type classes 
are used for abstract data types. It seems to me that this approach does 
not hide any parts of any definition, but only requires that all 
instances of class stack have functions pop and push of the correct 
types. I am interested in hiding parts of definitions.

In the report, I did not find any mention of a requirement to have 
different modules in separate files, but I have not managed to put 
several modules in the same file using ghci.

I would like to keep my small program in one literate-haskell tex-file 
and still be able to hide some definitions from others.

Is this possible?

One option would of course be to write a script that separates the code 
into different and then compiles the entire program.


Thanks in advance!

/ johan grönqvist



More information about the Haskell-Cafe mailing list