Questions tagged [church-encoding]

Questions about the Church encoding, a way to represent data using functions, and the Boehm-Berarducci encoding, a transposition of it to a typed setting. For questions primarily about the related Scott and Mogensen-Scott encodings, there is [scott-encoding].

Related Tags: , .

93 questions
1
vote
1 answer

Church encodings (conditionals)

I'm trying to write out some lambda calculus, but I can't get church conditionals to work. I should probably say that I'm a Haskell noob. I've looked at solutions online and on SO, but they all involve introducing a new type and other tricks, but I…
antimatter
  • 3,240
  • 2
  • 23
  • 34
1
vote
3 answers

Church numerals: How should I interpret the numbers from expressions?

Can someone explain to me using substitutions how we get a number "zero" or the rest of natural numbers? For example the value: "zero" λf.λx.x if I apply this expression on an another expression: "(λf.(λx.x)) a" then using…
Erhan Bagdemir
  • 5,231
  • 6
  • 34
  • 40
0
votes
1 answer

Church numerals, rigid type and infinite type

I was trying to implement the Church numeral predecessor function pred, then I referred to the wikipedia page about church encodings. According to it I wrote the following {-# LANGUAGE ScopedTypeVariables, RankNTypes #-} module Church where newtype…
farmerzhang1
  • 41
  • 1
  • 4
0
votes
1 answer

Understanding church numerals

I'm working my way through SICP, and it gives the following definition for zero for Church Numerals: (define zero (lambda (f) (lambda (x) x))) I have a few questions about that: Why the complicated syntax? It seems to be quite readable by just…
David542
  • 104,438
  • 178
  • 489
  • 842
0
votes
1 answer

How to iterate or repeat untyped function n times?

I'm practicing with OCaml compiler and I'm doing a small assignment where we have to implement Church numerals defined as: zz = pair c0 c0; ss = λp. pair ( snd p) ( plus c1 (snd p)); prd = λm. fst (m ss zz ); and to calculate the ss i wanna…
0
votes
1 answer

Defining a function to represent integers in Church numerals (DrRacket)

I am trying to define a procedure that takes an integer and returns its representation in Church numerals. Could any one please help me figure out the mistake I am making? The following code it's what I have been able to do so far. (define succ …
stcol
  • 131
  • 1
  • 11
0
votes
2 answers

How to return the Church number

I want to change decimal encoding number to chruch encoding number ? (define (encode n) (lambda(fn)(lambda(x) (funPower (fn n)x)))) What's wrong with my code? Thank you.
0
votes
1 answer

Printing Church Booleans

The following code is meant to print Church encoding of booleans as Haskell's Bool: {-#LANGUAGE FlexibleInstances #-} instance Show (t -> t -> t) where show b = show $ b True False Which leads to this error: :4:21: error: • Couldn't…
Bob
  • 1,713
  • 10
  • 23
0
votes
1 answer

Coq doesn't recognize equality of dependent list

I made a question before, but i think that question was bad formalized so... I am facing some problems with this specific definition to prove their properties: I have a definition of a list : Inductive list (A : Type) (f : A -> A -> A) : A -> Type…
0
votes
1 answer

How to encode a Deferred type with Church?

With functions we can abstract from any type. Here is the Option type as an example: const Some = x => y => k => k(x); const None = y => k => y; const sqr = n => n * n; const run = f => t => t(f); const x = Some(5) (0), y =…
user10675354
0
votes
4 answers

Church encoding of lists using right folds and difference lists

Here is the sequential question after How to store data of a functional chain of Monoidal List? and Extracting data from a function chain without arrays and here I would like to express my respect and appreciation for contributors to my Questions,…
user6440264
0
votes
1 answer

reduction steps for successor of 1 with Church numerals

I am trying to understand which are the right steps to perform the following reduction following the normal order reduction. I cannot understand which is the correct order in which I should perform the reduction, and why, in this expression:…
elena
  • 889
  • 2
  • 11
  • 19
0
votes
1 answer

Typed/Racket: given Natural number defined type need multiply two numbers function to created

Given the following defined structures and type need to write multiply two numbers function. Having trouble to do that. Any advice will be greatly appreciated. (define-struct Zero ()) (define-struct Succ ([n : Nat])) (define-type Nat (U Zero…
Lyudmila
  • 1
  • 1
0
votes
1 answer

What does this haskell expression mean

I just started learning about Haskell and I'm trying to use the lambda calculus in Haskell. I found this expression which converts a church numeral to a number but I can't seem to figure out what the 0 in this expression means. I can't find it…
user4424299
0
votes
1 answer

Recursion for church numerals in scheme

I have defined Church numeral zero and some other standard functions on church numerals according to Wikipedia definitions as following: (define n0 (λ (f x) x)) (define newtrue (λ(m n) m)) (define newfalse (λ(m n) n)) (define iszero (λ(m)…