开发者

Iteration function in lambda calculus

开发者 https://www.devze.com 2023-02-28 07:57 出处:网络
I ha开发者_开发知识库ve a function like this iter :: Int -> (a -> a) -> a -> a iter n f a = f (f ... (f a) .. )

I ha开发者_开发知识库ve a function like this

iter :: Int -> (a -> a) -> a -> a    
iter n f a = f (f ... (f a) .. )

how can i define such function in un-typed lambda calculus ?

any hint/help will be appreciated.


Numbers do not exist per se in pure lambda calculus. You have to design a representation for numbers (and show that indeed those behave like numbers). The basic idea is that you can define numbers so that they are exactly the iteration function you need : n would be a lambda term that, when given a function f, compute the nth iteration of f.

This is an idea known as Church Encoding.


iter == (rec g (fn f (fn n (fn x ((= n 0) x (g f (- n 1) (f x))))))) 
0

上一篇:

:下一篇

精彩评论

暂无评论...
验证码 换一张
取 消