Information hiding in Erlang

James Hague jhague@REDACTED
Fri Apr 28 03:21:49 CEST 2000

> Does Erlang
>provide mechanisms for encapsulating data structures, or is lack of
>information hiding just something to be accepted when programming a
>functional language?

One simple trick is to put an atom in your data structure and check for 
it.  So you could represent a priority queue as {priority_queue, Queue}.  
Then each routine that operated on it could be of the form:

insert({priority_queue, Queue}) -> ...

This isn't bulletproof, but covers you in most cases.  In general, I try 
not to worry too much about such things.  After all, I could have a 
routine that accepted three parameters, all integers, and I can't check 
if the user gets the order wrong.  Some advice I've heard is to avoid 
thinking of other programs in the system as attacking microbes, and 
assume they'll play nice in general :)

Erlang is one of the few functional languages that's dynamically typed.  
In other functional languages there's much formalism to make sure that a 
priority queue is indeed a priority queue, but it's debatable if the 
effort is indeed worth the result.


More information about the erlang-questions mailing list