[Haskell-beginners] Haskell data structures: cheap immutable manipulation and nested equality?

Anand Patil anand.prabhakar.patil at gmail.com
Fri Sep 4 05:38:49 EDT 2009


Hi all,


I'm slowly shopping around for a functional language. The first one I
seriously considered was Clojure, because of its agents; but I'm now
realizing that most of my concurrency needs can be met using 'par' and
'seq', so I'm thinking about giving Haskell a closer look.

However, Clojure's collections (maps, lists, vectors, sets) have a
couple of features that I would really miss:


- Cheap 'manipulation'. In the following:

user=> (def m {:a 1 :b 2})
#'user/m1
user=> (assoc m :a 3)
{:a 3, :b 2}

the 'assoc' function produces a new map which actually shares
structure with m, meaning it doesn't need to make a full copy in
memory; but it also leaves m unchanged. This works efficiently even
for nested, mixed collections.


- Cheap equality by value:

user=> (= m {:a 1 :b 2 :c {:d 3 :f 4}})
false
user=> (= m {:a 1 :b 2})
true

If I understand correctly, equality is computed based on some kind of
hash rather than by comparing the two maps element by element, so it's
efficient even for large and/or nested collections.


Do Haskell's data structures have analogous properties? If not, are
there libraries providing such data structures?


Thanks,
Anand


More information about the Beginners mailing list