Skip to content

linked-list: Suspicious alternative for functional languages #193

Closed
@NobbZ

Description

@NobbZ

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 languages that do not have good support for mutability (such as Elixir or Erlang), you may choose to implement a functional list where shift and pop have amortized O(1) time. The simplest data structure for this will have a pair of linked lists for the front and back, where iteration order is front ++ reverse back.

In a commit of the afforementioned PR, I already did a quick comment:

https://github.com/cebial/x-common/commit/552006a4610f917233e604ace3e964158ad01d6b#diff-25093f3da30fc2fdff5ad6a3967a7dfbL29

So this paragraph is describing an Okasaki-Functional-Double-Ended-Queue. This is not comparable with Doubly-Linked-Lists in any way.

Perhaps we should split this exercise up into this one and describe it in a imperativ way only while creating another exercise which does require you to implement a dequeue.

Another way to interprete this paragraph is very similar to a zipper as in zipper.md. If it is meant like a zipper we should probably don't do this exercise in languages which are immutable only and stick to that zipper-exercise.

Are there any further opinions on this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions