Tying the knot is a technique in which you can create circular data structures in the absence of mutation by referencing a yet to be produced value.
Questions tagged [tying-the-knot]
27 questions
5
votes
0 answers
How to preserve native cyclic list structure during transformations in Haskell?
I'm studying graph-like things handling in Haskell using 'tying the knot' technique. I suppose, cyclic lists is just kind of infinite list internal implementation, so in ideal world one should not care about subj. But it can have dramatic effect on…
![](../../users/profiles/4094574.webp)
Alexey Birukov
- 932
- 5
- 18
5
votes
3 answers
Is it possible to do a search on a graph constructed with the tying-the-knot strategy?
The tying-the-knot strategy can be used to construct graphs such as, using a simple two-edged graph as an example:
data Node = Node Node Node
-- a - b
-- | |
-- c - d
square = a where
a = Node b c
b = Node a d
c = Node a d
d =…
![](../../users/profiles/1031791.webp)
MaiaVictor
- 45,122
- 42
- 127
- 254
4
votes
1 answer
Level-order repminPrint
repmin problem is pretty well-known. We are given a data type for trees:
data Tree a = Leaf a | Fork (Tree a) a (Tree a) deriving Show
We need to write a function down (repmin) which would take a tree of numbers and replace all numbers in it by…
![](../../users/profiles/11143763.webp)
Zhiltsoff Igor
- 1,696
- 5
- 21
4
votes
1 answer
Functional Pearl: Implementing trace in JavaScript
Ross Paterson: Arrows and Computation introduces the trace function (on page 11):
trace :: ((a, c) -> (b, c)) -> a -> b
trace f a = let (b, c) = f (a, c) in b
The trace function is useful for modularizing the magic feedback step in circular…
![](../../users/profiles/783743.webp)
Aadit M Shah
- 67,342
- 26
- 146
- 271
3
votes
2 answers
Birecursively defining a doubly infinite list of lists
Context
I asked about patching a recursively-defined list the other day. I'm now trying to bring it up a level by operating on a 2D list instead (a list of lists).
I'll use Pascal's triangle as an example, like for example this beautiful…
![](../../users/profiles/12274.webp)
JB.
- 34,745
- 10
- 79
- 105
3
votes
2 answers
Tie-the-knot in 2 dimensions (was: tying the knot with a comonad)
Edit: The original question was "tying the knot with a comonad", but what really helped here is a two-dimensional knot tying with U2Graph from cirdec. Original question (until Anwser):
I want to tie the knot with data that originates from a…
![](../../users/profiles/412549.webp)
Franky
- 2,179
- 2
- 15
- 22
3
votes
4 answers
Self-reference in data structure – Checking for equality
In my initial attempt at creating a disjoint set data structure I created a Point data type with a parent pointer to another Point:
data Point a = Point
{ _value :: a
, _parent :: Point a
, _rank :: Int
}
To create a singleton set, a…
![](../../users/profiles/459877.webp)
beta
- 2,177
- 17
- 29
2
votes
3 answers
Mutually recursive evaluator in Haskell
Update: I've added an answer that describes my final solution (hint: the single Expr data type wasn't sufficient).
I'm writing an evaluator for a little expression language, but I'm stuck on the LetRec construct.
This is the language:
type Var =…
![](../../users/profiles/2597.webp)
Tom Lokhorst
- 12,397
- 5
- 50
- 69
1
vote
1 answer
How does repmin place values in the tree in Haskell?
I really like the repmin problem:
Write down repmin :: Tree Int -> Tree Int, which replaces all the numbers in the tree by their minimum in a single pass.
If I were writing something like this in python, I would go for passing values by their…
![](../../users/profiles/11143763.webp)
Zhiltsoff Igor
- 1,696
- 5
- 21
1
vote
0 answers
Haskell: handling cyclic dependencies while tying the knot
While writing a programming language that will feature local type inference (i.e. it will be capable of inferring types with the exception of function parameters, like Scala), I've run into a problem with cyclic dependencies.
I perform…
![](../../users/profiles/4476886.webp)
SongWithoutWords
- 402
- 5
- 10
0
votes
1 answer
How to perform Tying the Knot/define observable recursively using iteself in Rx.Net?
Sometimes the business logic seems to be able to naturally modeled by some recursive defined observables. Here is one example:
interface Demo {
IObservable userCommands;
IObservable> processes;
…
![](../../users/profiles/3813428.webp)
soar0x48
- 499
- 3
- 15
0
votes
1 answer
Non-exhaustive patterns in aux function for tying the knot
I am trying to write a function in Haskell that takes a table and pads up cells of each column according to the maximum size of a string in that column. The way I am doing this is by using the technique - tying the knot. Here is the function that I…
![](../../users/profiles/1779564.webp)
Iguana
- 147
- 7