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 7528121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:17:25+00:00 2026-05-30T04:17:25+00:00

Recently I was introduced to this OCaml code which in Haskell can be written

  • 0

Recently I was introduced to this OCaml code which in Haskell can be written as:

data DL a = DL [a] a [a]

create [] = error "empty list"
create (x:xs) = DL [] x xs

next (DL pr x (h:tl)) = DL (x:pr) h tl
next _ = error "end of dlist"

prev (DL (p:pr) x tl) = DL pr p (x:tl)
prev _ = error "start of dlist"

which I though was not a proper doubly-linked list implementation, as it creates new storage on traversal. OTOH there’s this Haskell code:

data DList a = Leaf | Node { prev::(DList a), elt::a, next::(DList a) }

create = go Leaf
  where go _    []     = Leaf
        go prev (x:xs) = current
            where current = Node prev x next
                  next    = go current xs

Can we say that it is only this code that’s true dl-list?

Can we rely on this code to introduce true sharing of nodes of the dl-list, so that no new storage is created on traversal?

Is the same-named variable in Haskell always referring to the same “thing” or might separate occurrences of the same-named variable refer to separate copy of the same thing? (edited to add emphasis).

  • 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-05-30T04:17:26+00:00Added an answer on May 30, 2026 at 4:17 am

    I would suggest that the latter is the “correct” implementation, yes.

    I do not have facts with which to back that up, but it would seem to me, given my understanding of the GHC implementation, that the latter should work how you’d expect a double-linked list to work.

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

Sidebar

Related Questions

I recently introduced HTML into some RSS feeds that I publish (which up to
We recently introduced PostSharp into our code base and the compile time of our
I have recently been introduced to the new Access 2007 feature which is multivalued
I recently introduced multi-stroke gestures into my application. This is a preference so I
I have an annoying error which I can't solve for quite a while. I
Having recently introduced an overload of a method the application started to fail. Finally
I am recently introduced to the test-driven approach to development by my mentor at
I recently started working in Java and was introduced to the wild and crazy
Recently, I've been dealing with an error with accessing MAPI via the .NET framework
After competing in and following this year's Google Code Jam competition, I couldn't help

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.