I have 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)))))))
(let ((p (fn u (fn v (v ((u u) v))))) (Y (p p)) (iter (Y (fn (lazy iter) (fn (n f a) ((eqw n 0) a (iter (subw n 1) f (f a)))))))) (iter 3 (fn x (mulw x x)) 2)) and also as: ((label iter (fn (n f a) ((eqw n 0) a (iter (subw n 1) f (f a))))) 3 (fn x (mulw x x)) 2)((label iter (fn (n f a) ((eqw n 0) a (iter (subw n 1) f (f a))))) 3 (fn x (set (cdr x) (cons x nil))) (cons nil nil))
...mean? (I know what you think it means, but that's exactly where your problem is.)