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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:40:56+00:00 2026-05-11T00:40:56+00:00

In reading Haskell-related stuff I sometimes come across the expression tying the knot, I

  • 0

In reading Haskell-related stuff I sometimes come across the expression “tying the knot”, I think I understand what it does, but not how.

So, are there any good, basic, and simple to understand explanations of this concept?

  • 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. 2026-05-11T00:40:57+00:00Added an answer on May 11, 2026 at 12:40 am

    Tying the knot is a solution to the problem of circular data structures. In imperative languages you construct a circular structure by first creating a non-circular structure, and then going back and fixing up the pointers to add the circularity.

    Say you wanted a two-element circular list with the elements ‘0’ and ‘1’. It would seem impossible to construct because if you create the ‘1’ node and then create the ‘0’ node to point at it, you cannot then go back and fix up the ‘1’ node to point back at the ‘0’ node. So you have a chicken-and-egg situation where both nodes need to exist before either can be created.

    Here is how you do it in Haskell. Consider the following value:

    alternates = x where    x = 0 : y    y = 1 : x 

    In a non-lazy language this will be an infinite loop because of the unterminated recursion. But in Haskell lazy evaluation does the Right Thing: it generates a two-element circular list.

    To see how it works in practice, think about what happens at run-time. The usual ‘thunk’ implementation of lazy evaluation represents an unevaluated expression as a data structure containing a function pointer plus the arguments to be passed to the function. When this is evaluated the thunk is replaced by the actual value so that future references don’t have to call the function again.

    When you take the first element of the list ‘x’ is evaluated down to a value (0, &y), where the ‘&y’ bit is a pointer to the value of ‘y’. Since ‘y’ has not been evaluated this is currently a thunk. When you take the second element of the list the computer follows the link from x to this thunk and evaluates it. It evaluates to (1, &x), or in other words a pointer back to the original ‘x’ value. So you now have a circular list sitting in memory. The programmer doesn’t need to fix up the back-pointers because the lazy evaluation mechanism does it for you.

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

Sidebar

Related Questions

When reading Wikipedia's entry on Haskell 2010 I stumbled across this: -- using only
I started reading about GADT in Haskell Wiki but didn't feel quite comfortable understanding
When I open a file for reading in Haskell, I've found that I can't
I was reading a research paper about Haskell and how HList is implemented and
I'm reading through A Gentle Introduction to Haskell, and early on it uses this
I just have started to learn Haskell and combine reading books and tutorials with
Firstly, Real World Haskell , which I am reading, says to never use foldl
I have been reading Real World Haskell , and I am nearing the end,
I'm reading through Learn You a Haskell and reached a spot where I'm trying
I am reading this tutorial on Haskell . They define function composition as the

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.