Questions tagged [fixpoint-combinators]

Questions about fixed-point combinators, used to encode recursion. For fixed-point arithmetic, use [fixed-point] instead. For the numerical method, used [fixed-point-iteration] instead.

A fixed-point (or fixpoint) combinator produces fixed points of functions given to it. If fix is such a combinator, we have fix f = f (fix f).

The best known fixpoint combinator is the Y combinator, which makes it possible to encode recursive definitions in the untyped lambda calculus. It has its own tag, . Another example is Haskell's fix function, which is of necessity different from the Y combinator (see Y Combinator in Haskell).

There are also type-level fixpoint combinators, such as Haskell's Fix type constructor, which also fall under the scope of this tag. When these are concerned, depending on the focus of the question it may be appropriate to use or in addition to, or instead of, .

77 questions
2
votes
1 answer

Fixed-point combinator in F#

This would not work: let rec fix f = f (fix f) The solution is to add an extra parameter: let rec fix f x = f (fix f) x Is there a way to do this using lazy and Lazy.force instead?
ThePiercingPrince
  • 1,803
  • 9
  • 19
2
votes
2 answers

Why not letrec as fix?

In the paper Fixing Letrec: A Faithful Yet Efficient Implementation of Scheme’s Recursive Binding Construct by Dybvig et al. it is said that (emphasis mine): A theoretical solution to these problems is to restrict letrec so that its left-hand…
Rhangaun
  • 1,262
  • 2
  • 14
  • 34
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…
Zhiltsoff Igor
  • 1,696
  • 5
  • 21
1
vote
1 answer

Complexity of computing Fibonacci sequence as a fixpoint

I have realised that the following program fibMap :: [Integer] -> [Integer] fibMap xs = 1 : 1 : (zipWith (+) xs $ tail xs) …
mna
  • 273
  • 2
  • 8
1
vote
1 answer

Attach extra information at every level of a recursive data type?

(This is not specifically a Haskell question.) I have a recursive data structure. I would like to attach some kind of extra information at every level of it. Here's a simplified example, in which I'm adding either an X or a Y to every level of a…
1
vote
3 answers

a fixed point for fix :: Eq a => (a -> a) -> a -> a

Hello everyone I'm trying to implement the higher-order function fix, which computes an attractive fixed point of an arbitrary function f :: a -> a from an initial point x. That is, a fixed point of the form fᴷ(x) for a given f and x. --…
Alaa Alsayed
  • 119
  • 7
1
vote
1 answer

Delaying Evaluation with Abstractions in the Y-Combinator

I am having some problem wrapping my head around how evaluation delaying works. I am trying to understand it with the Y-Combinator: If we write a simple version of the Y-Combinator we get problems with infinite recursion: Ysimple = (lambda f :…
1
vote
2 answers

Haskell school of expression fix function

So I am reading Paul Hudak's book "The Haskell School of Expression" and am stuck on an exercise in there. Here it goes Suppose function fix is defined as fix f = f (fix f) What is the principal type of fix? That one I know, it's b -> b -> b But…
Abdul Rahman
  • 1,174
  • 14
  • 32
1
vote
1 answer

Guessing the type of fixed-point combinator

My question is related to "fixed point combinator". According to this Wikipedia page section a function fix such that fix f = f (fix f) is of type (or at least can be of type) (a -> a) -> a Can someone explain me why?
godot
  • 1,205
  • 12
  • 27
1
vote
1 answer

Haskell type and fix recursion examples

When reading about fix because I was interested in having recursive lambdas in my code I came upon this particular example of code (from Here): fix (\rec n -> if n == 0 then 1 else n * rec (n-1)) 5 Now ignoring the type signature of fix I feel…
1
vote
2 answers

Haskell "fix" keyword failed on declaring a recursive lambda function

Seems a function should have a name to be recursive(in order to call itself), so how does a lambda function be recursive? I searched wikipedia and it says this could be done by a "Y-combinator". I don't have much math theory backgroup, it just tell…
vik santata
  • 2,525
  • 5
  • 24
  • 47
0
votes
3 answers

How to write a Show instance for Mu recursive types

I want to write an instance of Show for lists of the following type: newtype Mu f = Mu (forall a. (f a -> a) -> a) data ListF a r = Nil | Cons a r deriving (Show) type List a = Mu (ListF a) Module Data.Functor.Foldable defines it, but it converting…
0
votes
3 answers

Y-combinator does not seem to have any effect

I tried using the y-combinator (in both Lua and Clojure) as I thought that would allow me to exceed the size of default stack implementations when using recursion. It seems I was mistaken. Yes, it works, but in both of these systems, the stack…
0
votes
1 answer

Find least fixpoint of a function

If I have this Haskell function: Consider the following Haskell function f : f :: Int -> Int f 0 = 1 f x = x * x * f (x - 1) Then how can I calculate its fixpoint and the least fixpoint (in closed form)? The answer to this question is : How is…
Waqar Ahmed
  • 4,682
  • 1
  • 19
  • 38
0
votes
1 answer

Fix point function does not find my fix point

So as to understand the fix function, from Control.Monad.State, fix :: (a -> a) -> a, I have this little code in modifyValue, that increments an integer until 49, then the function always returns 50. import Control.Monad.State type StateVal =…
Stephane Rolland
  • 34,892
  • 31
  • 111
  • 159