
Purely Functional Data Structures in Scala - vkostyukov
http://www.slideshare.net/vkostyukov/purely-functional-data-structures-in-scala-26175521
======
chollida1
For those of you who have an interest in functional languages, let me throw
out this book:

[http://www.amazon.ca/Purely-Functional-Structures-Chris-
Okas...](http://www.amazon.ca/Purely-Functional-Structures-Chris-
Okasaki/dp/0521663504)

I just can't say enough good things about it. The code is in ml but there is a
Haskell port of the data structures.

It's a small book so its easy to read and digest in a couple of weeks.

~~~
rustc
I've heard lots of good things about this book, it's on high priority on my
"next to read" list.

Can you or anyone else recommend more books related to FP algorithms, concepts
in general (which are not necessarily language specific)?

~~~
jcurbo
Same here, I came in to post about that exact book.

There's also Pearls of Functional Algorithm Design which I have yet to read.
[http://www.amazon.com/Pearls-Functional-Algorithm-Design-
Ric...](http://www.amazon.com/Pearls-Functional-Algorithm-Design-
Richard/dp/0521513383/)

In general you've got stuff like Introduction to Algorithms
([http://www.amazon.com/Introduction-Algorithms-Thomas-H-
Corme...](http://www.amazon.com/Introduction-Algorithms-Thomas-H-
Cormen/dp/0262033844/)) and the Algorithm Design Manual
([http://www.amazon.com/Algorithm-Design-Manual-Steven-
Skiena/...](http://www.amazon.com/Algorithm-Design-Manual-Steven-
Skiena/dp/1849967202/)) both of which I have seen mentioned as good books. I'm
in a grad school-level algorithms class that just started using the former
(which is language agnostic, but we are doing our implementations in Java) and
it looks pretty good to me.

------
fooyc
Great slides. Very interesting because implementing immutable data structures
is not obvious.

I'm having a hard time figuring out a use case for some of these purely
functional structures.

For instance, the queue: if you dequeue concurrently, you end up dequeuing the
same element twice:

    
    
        q Queue
        // thread A
        q, elem = q.dequeue()
        // thread B
        q, elem = q.dequeue()
        // elem can be the same in both A and B
    

If you enqueue concurrently, only one element will end up being enqueued:

    
    
        q Queue
        // thread A
        q = q.enqueue(elemA)
        // thread B
        q = q.enqueue(elemB)
        // only one of elemA or elemB is queued
    

So if the structure is useless for concurrency (without external
synchronization), what's his purpose?

~~~
herge
If both queues are immutable, enqueuing/dequeuing is just creating a new queue
with/without the element in it.

So thread A and thread B can share the same queue, but will create two
different queues (one for each thread) when enqueuing to it.

Now if you want to share a queue between two threads, you have to simply
synchronize between the threads and share each of their current versions of
the queue.

~~~
fooyc
That was my point :)

