Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7885769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:09:19+00:00 2026-06-03T05:09:19+00:00

Is it possible to have a doubly linked list in Haskell, and what’s the

  • 0

Is it possible to have a doubly linked list in Haskell, and what’s the ideal solution to implementing them? I’m implementing a scene graph where every widget has a parent as well as a child, and it’s beneficial to look both up and down the graph.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:09:21+00:00Added an answer on June 3, 2026 at 5:09 am

    It isn’t really practical to have a doubly linked list in Haskell, because you have to construct it all at once.

    For example, imagine that you have a list [1, 2, 3, 4, 5] that you want to make doubly linked. Now, let’s imagine how the list is represented:

    data DoubleList a
      = LeftEnd  a (DoubleList a)
      | Middle   a (DoubleList a) (DoubleList a)
      | RightEnd a (DoubleList a)
    

    (I use two different constructors for the two ends for simplicity)

    To build the list above, you have to first construct the first element:

    let e1 = LeftEnd  1 ...
    

    But to construct the first element, you already need to have the second element:

    let e1 = LeftEnd  1 e2
        e2 = Middle   2 e1 ...
    

    And for the second element, you need the third, etc:

    let e1 = LeftEnd  1 e2
        e2 = Middle   2 e1 e3
        e3 = Middle   3 e2 e4
        e4 = Middle   4 e3 e5
        e5 = RightEnd 5 e4
    

    This is possible to do in Haskell due to lazy evaluation; this strategy is called “tying the knot” (And you don’t have to literally put it all in one let block; you can divide up the construction into functions)

    But, in other words, to make a doubly-linked list, you need to construct it all at once, and if you ever want to change any part of it, you either need to use a Zipper or just make a complete copy of it every time.

    I would recommend to instead use Data.Sequence, which is an optimized finger-tree based sequential storage implementation. It supports very fast insertion, deletion and iteration while still being a purely functional data structure.

    Otherwise, you might want to just use Zippers, but use them for Trees instead of for Lists. More information about Zippers can be found on the Haskell Wiki. Zippers would fit very well in this situation, because they offer the exact functionality that you’re after: if you visit a tree with a Zipper, you gain access to the “parents” of the part of the tree that you’re visiting, but the tree itself doesn’t have to contain the parent references.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Single Linked List is Palindrome or not Suppose i have a link
is it possible to have a specific element on top of the list? backgoround:
Im trying to remove a single node from a doubly threaded linked list. What
I have looked at most threads here about Doubly linked lists but still unclear
[SOLVED] So I decided to try and create a sorted doubly linked skip list...
I am writing a program in c++ which implements a doubly-linked list that holds
is it not possible to have both CLICK and DOUBLE_CLICK on the same display
Is it possible have two projects with the same name in flex builder? Here
is possible to have a separator between elements of a GridView? Thanks
Is it possible to have a many to many relationship between two tables, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.