1

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.

4
  • 1
    you might get a better response at: cstheory.stackexchange.com Commented Apr 25, 2011 at 13:45
  • 1
    @Dhaivat: Sure, if you count "This question is for research-level questions only - please read the FAQ" as a better response. Commented Apr 25, 2011 at 14:06
  • Its not really research level, but, I doubt that one could find many people who work with lambda calculus on SO, seeing that it is a highly "work-based" community. Commented Apr 25, 2011 at 15:22
  • 2
    The question is bogus: what does ... mean? (I know what you think it means, but that's exactly where your problem is.) Commented Apr 25, 2011 at 18:06

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer, you are absolutely right, i figured it out later, it would give the Church numerals representation in lambda calculus
0
iter == (rec g (fn f (fn n (fn x ((= n 0) x (g f (- n 1) (f x))))))) 

2 Comments

I designed and implemented a lisp dialect that is strongly typed with implicit types where the iter function could be written as follows using y-comb: (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)
using the iter function we can construct a cyclic structure as follows: ((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))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.