-
Notifications
You must be signed in to change notification settings - Fork 3
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
Is there no O(1) head function? #16
Comments
Very good point! If one is to implement
Option (2) is very pragmatic for Elixir (and is even a suggestion from the original paper). Regarding option (1), if I understood the suggestion correctly, Option (1) seem quite attractive and elegant. It'll just make the API a bit clunkier to use, since the user will have to manually force the returned "thunk" when using I'd view option (2) as a quicker and good enough solution for now, if one needs to implement that function. After that, (1) would be a possible further improvement on that. |
No, it's simpler than that. The laziness resides in the |
After reading the original article by Ross & Paterson, I came across the part where they talk about how the performance differs slightly for strict languages as compared to lazy languages. One situation is the
head
function. In a lazy language, one simply defineshead
in terms ofview_l
. But this only has O(1) complexity because the computation of the tail is lazy. In a strict language such as elixir,view_l
(hallux/lib/hallux/internal/finger_tree.ex
Line 215 in 1b154f7
head
drops it again.There are two ways out of this:
:m
field in the%Deep{}
structhead
function that doesn't compute the tailOption 2. adds some duplicated code and only patches this particular function, but option 1. requires changes in the whole
Fingertree
module.The text was updated successfully, but these errors were encountered: