-
-
Notifications
You must be signed in to change notification settings - Fork 544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
linked-list: Suspicious alternative for functional languages #193
Comments
I think the right move is to not implement the linked-list in functional languages. We should remove the suspicious alternative from the README. If functional languages have implemented linked-list with the alternative, we should consider deprecating it. If the zipper problem is sufficiently close to the dequeue, I would not want to implement a new exercise specifically for the dequeue. |
The Zipper is actually far away from a dequeue, its just another way to read that paragraph. The functional dequeue is something that holds two lists, one "front" and one "back" queue. One appends by "consing" to the back, and pops by taking the head from the front. If the front is empty when one tries to pop, the "back" is reversed and used as front. A Zipper on the other hand is more similar to a Visitor in OOP. When created it takes the original datastructure and converts parts of it into an internal representation. When talking about a list-zipper this were exactly 2 lists. One containing all items before the current position with the most recent visited as its head (so it is reversed) and a list containing the items after the current position. This were a very simple Zipper. You can walk this Zipper back and forth elementwise in O(1) (if it is implemented correctly) and as such you get similar runtime behaviour as with a doubly-linked-list, as long as you use its zipper. Also you can reconstruct the original list from any position in O(n), where n is the current position in the list. The Zipper from the actual exercise is more complex since it walks a binary tree, but also there you can go one step down or up in O(1) (if you consider copying the data has no cost), and also you are able to reconstruct the original tree from any position in O(n), with n beeing the depth in the tree of the current position. So implementing a functional dequeue (also called Okasaki-Queue because of his paper "Purely Functional Data Structures" from 1996) is completely different from implementing a Zipper (even for lists). |
Update gigasecond version test comments to be more clear for user
During reading the changes made by PR #188, I encountered some paragraph in the
linked-list.md
, which I do find is giving a suspicious alternative for implementing the exercise in functional languages:In a commit of the afforementioned PR, I already did a quick comment:
https://github.com/cebial/x-common/commit/552006a4610f917233e604ace3e964158ad01d6b#diff-25093f3da30fc2fdff5ad6a3967a7dfbL29
Are there any further opinions on this?
The text was updated successfully, but these errors were encountered: