Live data from Hacker News

Functional data structures in JavaScript with Mori

sitr.us

1–10 of 21 posts

Re: Functional data structures in JavaScript with Mori

#2
This is great. I never understood why underscore/lo-dash doesn't have a `conj` or a `concat`.

JavaScript's `push` mutates data which you'd think you'd want to avoid if you're using a functional library like underscore/lo-dash.

`concat` makes sense to leave out when you consider that arrays already have a `concat` function. But if that's the reasoning, why did underscore/lo-dash include `size` and `max` and all those other things that already exist?

Re: Functional data structures in JavaScript with Mori

#3
One nifty thing not covered here is that Mori also has an extremely efficient O(1) thaw to get a mutable copy of an immutable value and a O(1) freeze to get a persistent value from a mutable data structure (transient).

The performance of a transient vector is shockingly close to using a JavaScript array under Google V8 for adding new elements:

http://github.com/swannodette/mori#efficient-freezethaw

Re: Functional data structures in JavaScript with Mori

#5
Of course it is obligatory to mention the classic: Okasaki's "Purely Functional Datastructures" book.

http://www.amazon.com/Purely-Functional-Structures-Chris-Oka...

Also check out this link for additional data structures worked on since then or simply not included in the book:

http://cstheory.stackexchange.com/questions/1539/whats-new-i...

Re: Functional data structures in JavaScript with Mori

#6
post #5

Of course it is obligatory to mention the classic: Okasaki's "Purely Functional Datastructures" book. http://www.amazon.com/Purely-Functional-Structures-Chris-Oka... Also check out this link for additional data structures worked on since then or simply not included in the book: http://cstheory.stackexchange.com/questions/1539/whats-new-i...

Is this more required reading? Has anyone else's homework load doubled since college?

Re: Functional data structures in JavaScript with Mori

#7
post #5

Of course it is obligatory to mention the classic: Okasaki's "Purely Functional Datastructures" book. http://www.amazon.com/Purely-Functional-Structures-Chris-Oka... Also check out this link for additional data structures worked on since then or simply not included in the book: http://cstheory.stackexchange.com/questions/1539/whats-new-i...

A minor nit, most of the data structures provided through Mori via ClojureScript are not based heavily on Okasaki's work, rather they are based on Bagwell's paper on mutable Ideal Hash Trees http://lampwww.epfl.ch/papers/idealhashtrees.pdf and Rich Hickey's efficient immutable implementations in Java for Clojure

Re: Functional data structures in JavaScript with Mori

#8
post #4

I like that the article calls then "functional data structures". Every time I call them by their real name (persistent data structures), _at least_ one person will get confused and think I'm talking about serialization to disk.

Is is possible to construct a persistent data structure that is not referentially transparent? I suspect the answer is yes, depending on how you define side effects (example: a persistent array that logs operations).

Which would mean "functional" is a more general adjective than "persistent" since it includes both persistence and referential transparency.

Wikipedia[1] claims "There also exist persistent data structures which use destructible operations, making them impossible to implement efficiently in purely functional languages"

[1] https://en.wikipedia.org/wiki/Persistent_data_structure

Re: Functional data structures in JavaScript with Mori

#10
post #4

I like that the article calls then "functional data structures". Every time I call them by their real name (persistent data structures), _at least_ one person will get confused and think I'm talking about serialization to disk.

I consistently see the same problem. That is exactly why I use the word "functional".
Post reply on HN