# brianbec's WebLog

### Programming

##### A Hint and a Challenge
Ok, it's been quite a while since I issued the challenge to write the Y combinator in VB9 CTP without using recursive types, and no one has bitten yet (actually, the challenge was originally made to me by Erik Meijer and much of what I've done comes from Mark Shields). So I am going to drop a HUGE hint and re-issue the challenge. Review my blog to see how I did the early-bound version, using a universal representation for types. Now, instead of recursively defining a type U with a branch for functions from U-to-U, (drum roll), use exceptions to throw either integers or functions from U-to-U out of the combinators. Now, the top-level type is ... ?? That's the new puzzle, and I'm going to bring this episode to a close with that, hoping some adventurous reader will post the solution in the form of VB code, because I have some new wonders to talk about.

Published Thursday, August 3, 2006 3:44 PM by brianbec

Filed under: , ,

#### # re: A Hint and a Challenge@ Saturday, January 8, 2011 6:05 PM

[code]

Public Function Fix(Of T, TResult)(ByVal f As Func(Of Func(Of T, TResult), Func(Of T, TResult))) As Func(Of T, TResult)

Return Function(x)

Return f(Fix(f))(x)

End Function

End Function

[/code]

Note: The code could be made shorter by using the single line version of function.

Fibonacci Example.

[code]

Dim fib = Fix(Of Integer, Integer)(Function(f) Function(x) If(x <= 1, 1, f(x - 1) + f(x - 2)))

[/code]

[code]

Dim x=Fib(11)

[/code]