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
0 answers

How to encode two distinct Unit types using church encoding

I was studying Haskell and happened to know the church encoding of algebraic data types. For example, the unit type in Haskell can be encoded as a polymorphic function type. But one can also define a Unit' type that is isomorphic to Unit but…
1
vote
1 answer

How to revert beta-reductions to named functions in a lambda calculus-based system?

Well, suppose that I have a set of functional definitions (with a syntax tree) in church encoding : true : λx -> λy -> x false : λx -> λy -> y Giving the definition λx -> λy -> y, it is very clear how to return the named definition, applying a…
1
vote
3 answers

Going from Curry-0, 1, 2, to ...n

Following up from a previous question I asked about writing a curry function, How to create a make-curry function like racket has, I've started writing the fixed case for 0, 1, 2 -- they are very similar to Church Numerals which is pretty neat. Here…
David542
  • 104,438
  • 178
  • 489
  • 842
1
vote
1 answer

How to define a function with Church numerals in lambda-terms?

How can I express the following function by a lambda term? f(n) = T if n != 0. F if n = 0. n stands for a Church numeral. I know that 0 := λf.λx.x where λx.x is the identity function and all other natural numbers can be expressed by n := λf.λx.f (f…
1
vote
1 answer

System F Church numerals in Agda

I would like to test some definitions in system F using Agda as my typechecker and evaluator. My first attempt to introduce Church natural numbers was by writing Num = forall {x} -> (x -> x) -> (x -> x) Which would be used just like a regular type…
1
vote
2 answers

Church encoding of dependent pair

One can easily Church-encode pairs like that: Definition prod (X Y:Set) : Set := forall (Z : Set), (X -> Y -> Z) -> Z. Definition pair (X Y:Set)(x:X)(y:Y) : prod X Y := fun Z xy => xy x y. Definition pair_rec (X Y Z:Set)(p:X->Y->Z) (xy : prod X Y)…
Bob
  • 1,713
  • 10
  • 23
1
vote
1 answer

Church numerals and universe inconsistency

In the following code, the statement add'_commut is accepted by Coq but add_commut is rejected because of a universe inconsistency. Set Universe Polymorphism. Definition nat : Type := forall (X : Type), X -> (X -> X) -> X. Definition succ (n :…
Bob
  • 1,713
  • 10
  • 23
1
vote
1 answer

Is there a way to give curried arrow functions a type/tag?

Function encoded types (i.e. nested curried functions) have some drawbacks in Javascript: Their representation in the dev console is obfuscated (e.g. [Some(5), None] is displayed as [f, f]) Nothing stops you from applying a combinator to the wrong…
user10675354
1
vote
1 answer

TypeScript 3.0 error on `unknown` usage

Here, I test TypeScript3.0 unkown type. https://blogs.msdn.microsoft.com/typescript/2018/07/12/announcing-typescript-3-0-rc/#the-unknown-type TypeScript 3.0 introduces a new type called unknown that does exactly that. Much like any, any value is…
user6440264
1
vote
2 answers

Exponentiation function Haskell

How to get the exponentiation function in church numerals using Haskell? I'm trying to apply the rule, which is λxy.yx but something doesn't work right. exponentiation :: (Num a) => Func a exponentiation x y = y x
thali
  • 13
  • 3
1
vote
1 answer

How to define positive and negative integers and rational numbers in lambda calculus

I'm studying lambda calculus and only have basic knowledge about it. I read many of website and paper and understand the way that logic (T/F/and/or), predicate and successor work but I don't know how to accomplish other things in programming by…
1
vote
3 answers

Define the notion of "pairs" using higher-order logic

Revising for a course on automated reasoning and I don't quite understand how to answer this question: Show how the notion of pairs (x, y) can be defined in higher-order logic using a lambda abstraction. Define a function π1 that returns the first…
1
vote
1 answer

Find the most general types of the following lambda calculus terms

I am having trouble understand why these are the most general types for their respective Church numerals: 2 = λf.λx. f (f x) : (α → α) → α → α 1 = λf.λx. f x : (α → β) → α → β 0 = λf.λx. x : β → α → α I thought that all Church numerals had the…
1
vote
1 answer

Y-Combinator factorial in javascript works for numbers not for the Church numerals.

I managed to implement Church encoding and Y-Combinator using ES6 arrow function in javascript. But when I tried to evaluate the factorial function, FALSE = a => b => b TRUE = a => b => a ZERO = f => z => z ONE = f => z => f(z) SIX = f => z =>…
1
vote
1 answer

trying to understand church encoding in Scheme

I'm trying to understand the whole principal of church encoding through Scheme. I think I understand the basics of it such as Church numeral for 0 (define c-0 (lambda (f) (lambda (x) x))) Church numeral for 1 (define c-1 (lambda (f) (lambda (x) (f…
Ben
  • 2,518
  • 4
  • 18
  • 31