Re:Clojure: On the importance of recognizing and using maps
by weavejester on Friday March 13, 2009 @01:40PM
(#515092)
"Because many times, you don't want some parts of your program to know about the internal fields your datatype has, as the implentation can keep changing all the time."
There's no reason why you can't hide a data structure behind a set of functions in Clojure.
ML which uses ADTs solves this problem nicely. You can just write a module containing the map which implements two different signatures, one signature with the restricted set of fns, and another signature which will expose the map. Regular modules will import the restricted signature, while serialization or database interaction modules can import the map signature.
I like PLT scheme's unit system which comes from ML. It is better in two ways, units & signatures are first class values. And, you can use the powerful macro system to get rid of any repeated syntax pattern involved in exposing a map in two different ways.