96 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
2
votes
0
answers
46
views
How do I solve this infinitely recursive type problem I've created in Haskell with Church Numerals [duplicate]
data ChurchN a = ChurchN
{ numeral :: (a -> a) -> a -> a
, litRep :: String
}
next :: ChurchN a -> ChurchN a
next x = ChurchN
{
numeral = \f y -> f (numeral x f ...
4
votes
1
answer
136
views
Implementation of Church numeral multiplication in Haskell not working
I'm currently learning about Church encoding and I'm trying to implement the mul (multiply) function.
This is the correct implementation
mul cn cm = \f x -> cn (cm f) x
This (my implementation) ...
0
votes
1
answer
409
views
church number in rust
This is a church number implementation under rust, but there are some problems
,there is my code
use std::cell::RefCell;
use std::rc::Rc;
pub type Church<T> = Rc<dyn Fn(Rc<dyn Fn(T) -> ...
6
votes
2
answers
179
views
Sum/product of Church-encoded list of numbers does not type check
Following standard definitions of Church-encoded natural numbers and lists represented as right folds, I want to write a function that takes a list of numbers as its argument and returns sum of its ...
1
vote
0
answers
242
views
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 ...
0
votes
1
answer
107
views
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 ...
1
vote
1
answer
311
views
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, ...
1
vote
3
answers
424
views
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 ...
0
votes
1
answer
885
views
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 ...
0
votes
1
answer
440
views
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 ...
0
votes
1
answer
280
views
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 ...
1
vote
1
answer
392
views
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 ...
2
votes
0
answers
145
views
How to prove that the Church encoding, forall r. (F r -> r) -> r, gives an initial algebra of the functor F? [closed]
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) -> ...
0
votes
2
answers
1k
views
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.
-1
votes
2
answers
175
views
unfolding recursive expressions
I've been recently working with recursive expressions in Python.
An example of such expression is given as:
['+', [['*', ['i0','i1']], ['*', ['i2','i3']]]]
I'm attempting to transform expressions ...