Hacker News new | past | comments | ask | show | jobs | submit login

I was attracted to this viewpoint, especially as it makes serialization/deserialization easy. But there are good reasons behind using objects (and their dual, abstract data types). 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.

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.




"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.


You are right, i didn't mean to say otherwise. The original post had a critique of ADTs which i was responding to.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: