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

Using Comonad Fix Combinators

So I've been experimenting with fixed points lately and have finally struggled through regular fixed points enough to discover some uses; now I'm moving onto comonadic fixed points and I'm afraid I've gotten stuck; Here's a few examples of what I've…
Chris Penner
  • 1,835
  • 8
  • 14
3
votes
1 answer

Recursive functions vs recursive lambdas in Haskell

I am a bit confused. There is no problem with defining ordinary recursive functions in Haskell. At the same time there is the standard fix function for defining recursive lambdas via fixed points. But besides being less readable a recursive lambda…
Trident D'Gao
  • 15,993
  • 14
  • 77
  • 141
3
votes
2 answers

FIx data type in OCaml

How can the following data type from Haskell be expressed in OCaml or SML? newtype Fix f = In (f (Fix f))
Romildo
  • 465
  • 6
  • 18
2
votes
2 answers

Fixed Point Generator in C# Generics

I have tried to define a fixed point generator in C# that you see in many functional languages. I believe foldr is usually defined in terms of a fixed point generator sometimes. I'll show it's Haskell definition and then what I have in C#. Any…
Aaron Stainback
  • 3,164
  • 1
  • 27
  • 31
2
votes
0 answers

How to prove that the Church encoding, forall r. (F r -> r) -> r, gives an initial algebra of the functor F?

The well-known Church encoding of natural numbers can be generalized to use an arbitrary functor F. The result is the type, call it C, defined by data C = Cfix { run :: forall r. (F r -> r) -> r } Here and below, for simplicity, we will assume…
2
votes
1 answer

Can fix be tail recursive and thus expressed as a simple loop?

I can't figure out how to express fix as a tail recursive algorithm. Or is it already tail recursive? I am probably overthinking it... const fix = f => x => f(fix(f)) (x); // redundant eta abstraction due to eager eval const sum = fix(go => acc…
2
votes
1 answer

fix-point combinators in clojure

One of my favorite ways to test the power of a language I'm learning is to try and implement various fixed-point combinators. Since I'm learning Clojure (though I'm not new to lisps), I did the same for it. First, a little "testable" code,…
D. Ben Knoble
  • 3,649
  • 1
  • 18
  • 31
2
votes
1 answer

How to understand/use Haskell fix function

I see the following code in xmonad package: -- | Ignore SIGPIPE to avoid termination when a pipe is full, and SIGCHLD to -- avoid zombie processes, and clean up any extant zombie processes. installSignalHandlers :: MonadIO m => m…
McBear Holden
  • 5,179
  • 6
  • 31
  • 50
2
votes
1 answer

Define lists with least fixed point, sum, and product types

I want to define lists using only this type definitions: data Unit = Unit data Prod a b = P a b data Sum a b = L a | R b newtype Mu f = Mu (forall a . (f a -> a) -> a) I succeeded defining natural numbers as follows: zeroMu = Mu $ \f -> f $ L…
user3368561
  • 759
  • 6
  • 16
2
votes
1 answer

In what sense is one function "less defined" than another?

What I mean is that, from definition: fix f is the least fixed point of the function f In other words: the least defined x such that f x = x. The least defined value of any nullary type is undefined. There is some ambiguity here still as…
2
votes
1 answer

Can one express catamorphism through Data.Function.fix?

I have this lovely fixana function here that performs about 5 times faster than her sister ana. (i have a criterion report to back me on this) ana alg = Fix . fmap (ana alg) . alg fixana alg = fix $ \f -> Fix . fmap f . alg Can I express their…
2
votes
2 answers

How to use Functor instances with Fix types

Let's say I want to have a very generic ListF data type: {-# LANGUAGE GADTs, DataKinds #-} data ListF :: * -> * -> * where Nil :: List a b Cons :: a -> b -> List a b Now I can use this data type with Data.Fix to build an…
hgiesel
  • 4,699
  • 1
  • 21
  • 47
2
votes
2 answers

How McCarthy 91 function works

I have following function based on McCarthy 91 principle: mc91 :: Integer -> Integer mc91 n | n > 100 = n - 10 | otherwise = mc91 (mc91 (n + 11)) when I type in the prelude mc91 85 I've got 91. I could not configure it out, how it is…
softshipper
  • 26,415
  • 36
  • 123
  • 260
2
votes
2 answers

How would you implement a fixed-point operator (Y combinator) in F#?

I'm using F# to create a lambda calculus. I am currently stuck trying to figure out how I would implement the fixed-point operator (also called Y combinator). I think everything else is in order. Expressions are represented by the following…
klactose
  • 1,131
  • 2
  • 9
  • 26
2
votes
1 answer

U combinator on a fibonacci : how would you translate this code to python?

I am trying to learn about combinators and I am having trouble understand the example given at (Y overriding self-application). I think I am beginning to grasp the concept but I am still far from understanding. I would like to translate the…
JPCosta
  • 1,207
  • 10
  • 15