It is not possible to write the Y combinator in typed lambda calculus. However you need the Y combinator in order to write any useful programs, so typed functional languages like F#/OCaml get around this problem by introducing the let rec construct. Essentially let rec is the Y combinator built in to the language itself.

So a normal F# programmer would write your function as

1
let rec doAtoB b = if b < 0 then 1 else 1 + doAtoB (b-1)

However, with the presence of letrec you can of course write a fixed point combinator in terms of letrec. So a type-theoretic F# programmer could write

1
2
3
4
let rec fix f = f (fun x -> fix f x)

let a f b = if b < 0 then 1 else 1 + f (b-1)
let doAtoB = fix a

Where fix is the Y combinator you are looking for and you can isolate all use of letrec to this one function.

By on 12/5/2007 10:17 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper