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
6
votes
1 answer

How to use Y- Combinator; why does this infinite recursion return 9?

Y - Combinator I've been trying to learn about Y - Combinators (an explanation on that would be lovely as well) and came across an example from this wiki. An in depth explanation on the subject would be much appreciated in either Haskell or…
6
votes
1 answer

Fixed point combinator usage? Why a stack overflow here?

I am confused about something. I wanted to generate an example (in Clojure) demonstrating how a fixed point combinator could be used to evaluate the fixed point of a sequence that mathematically converges after an infinite number of applications but…
6
votes
3 answers

Fixed-Point Combinators

I am new to the world of fixed-point combinators and I guess they are used to recurse on anonymous lambdas, but I haven't really got to use them, or even been able to wrap my head around them completely. I have seen the example in Javascript for a…
5
votes
1 answer

Haskell AST Annotation with Fix

I am working on creating an AST in Haskell. I want to add different annotations, such as types and location information, so I ended up using fixplate. However, I can't find any examples online and am having some difficulty. I've set up my AST as…
5
votes
1 answer

Haskell: deriving Show for Fix types

I'm trying to implement a recursive datatype using recursion-schemes. I would like to be able to print it. import Data.Functor.Foldable data T1F a = Foo deriving Show type T1 = Fix T1F data T2 = Bar T1 deriving Show -- error here Error message: No…
Carl Patenaude Poulin
  • 4,468
  • 4
  • 17
  • 36
5
votes
2 answers

Recursion schemes using `Fix` on a data-type that's already a Functor?

Still working on my text editor Rasa. At the moment I'm building out the system for tracking viewports/splits (similar to vim splits). It seemed natural to me to represent this structure as a tree: data Dir = Hor | Vert deriving…
5
votes
1 answer

Fixed points of representational bifunctors

Edward Kmett's experimental roles package offers various utilities for lifting coercions, some of which I've pasted at the end of this question. The key class in the package is class Representational (t :: k1 -> k2) where -- | An argument is…
dfeuer
  • 44,398
  • 3
  • 56
  • 155
5
votes
1 answer

typeclass for repetitive actions until fixed point

i noticed a common pattern of executing an action until it stops having certain effects, when one knows that this signifies a fixed point (ie, there can be no future effects). is there a typeclass for this? is this covered by MonadFix? looking at…
4
votes
1 answer

Is it possible to write down a sharing fix point-free?

Edit: fix in this post stands for a fixed-point combination written down in Haskell in general, not just Data.Function.fix. It is widely known that fix could be non-sharing as GHC does not always eliminate common subexpressions: Long story short:…
Zhiltsoff Igor
  • 1,696
  • 5
  • 21
4
votes
1 answer

What is the fixed point of fix?

A recent poster best left anonymous attempted to implement the factorial function like this: f :: Int -> Int f = fix f This obviously didn't work out too well. But then I got to wondering: can I make it pass the type checker? What will its type…
dfeuer
  • 44,398
  • 3
  • 56
  • 155
4
votes
1 answer

Fixed point combinators for functions over custom types?

Most examples of the use of fixed point combinators involve functions that take integers to integers (e.g. factorial). In many cases the fixed point of a function over the real numbers will end up being an arbitrary rational or perhaps irrational…
4
votes
2 answers

Calculating fibonnacci numbers using fix

I am trying to understand how this factorial example works using the function fix :: (a -> a) -> a. Example: factabs :: (Num a, Eq a) => (a -> a) -> a -> a factabs fact 0 = 1 factabs fact x = x * fact (x-1) f :: (Num a, Eq a) => a -> a f = fix…
akonsu
  • 26,172
  • 26
  • 106
  • 175
4
votes
4 answers

What is fixed point?

I'm rewatching some of the earlier lectures on SICP. The notion of a fixed-point is a bit confusing to me. The fixed-point procedure: should I be thinking about it this way, "it's the way to find a fixed-point of a given function." So given f(2) =…
3
votes
1 answer

Fixed point of K combinator

The K combinator is K := (λxy.x) and the fixed point combinator is Y := λf.(λx.f x x) (λx.f x x). I tried to calculate YK: YK = (λx.Kxx)(λx.Kxx) = (λx.x)(λx.x) = (λx.x) = I So because YK is the fixed point of K: K(YK) = YK KI = I KIe = Ie = e for…
xuanji
  • 4,549
  • 2
  • 22
  • 33
3
votes
2 answers

Can fix only be typed in non-strict evaluated languages?

I write a runtime type checker in and for Javascript and have trouble to type fix: fix :: (a -> a) -> a fix f = ... fix (\rec n -> if n == 0 then 1 else n * rec (n-1)) 5 -- 120 The factorial function passed to fix has the simplified type (Int ->…
user6445533