Information hiding in Erlang

Jith Meganathan jith@REDACTED
Fri Apr 28 01:50:14 CEST 2000


Hi - I'm a newcomer to Erlang, and have been slowly working through the
_Concurrent Programming in Erlang_ book to learn the language. My
background is mostly in OOP, and thus, one of the aspects of Erlang I am
most uncomfortable with is the apparent lack of support for information
hiding.

I've attached a module I wrote implementing a simple priority queue with
operations to add and pop elements, and to view the element with highest
priority. The data structure used is a list of tuples, where each tuple
contains an element and a priority. In writing the module, I felt a
certain...nervousness at trusting callers to pass in a valid data
structure each time they invoked a function in the module. Does Erlang
provide mechanisms for encapsulating data structures, or is lack of
information hiding just something to be accepted when programming a
functional language?

Potential solutions seem to include the method used in the example
program (Program 5.6) on pp. 81 - 82 of _Concurrent Programming in
Erlang_, in which a server function stores data structures in their
current state, suspends until it receives a message to operate on them,
and after processing, invokes the function with the now-modified data
structures as arguments. I have also seen references to doing OOP in
Erlang, but am unsure of how common this approach is. In short, what is
the most natural mechanism to use in the language?

Regards,
Jith


~~~~~~~~~~~~~
Jith Meganathan
Vail Systems, Inc.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pq.erl
Type: application/x-unknown-content-type-erlang
Size: 2128 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20000427/afe09703/attachment.bin>


More information about the erlang-questions mailing list