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 n
th 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)))))))
精彩评论