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 03, 2006 3:44 PM by brianbec

Filed under: , ,

Comments

# re: A Hint and a Challenge@ Saturday, January 08, 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]

Adam Speight

# A Hint and a Challenge | Developers Blog@ Tuesday, July 19, 2011 4:28 AM

Pingback from  A Hint and a Challenge | Developers Blog

A Hint and a Challenge | Developers Blog