Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] Re: Y Combinator



Edward Middleton wrote:
John Fremlin wrote:
Edward Middleton wrote:
1. http://www.eecs.harvard.edu/~cduan/technical/ruby/ycombinator.shtml
If you looked at this code and actually understood what it was doing,
I think it is basically this: (well at least it has the same results
when I ran it)

def make_hash_func()
  Hash.new { |h, k| h[k] = make_hash_func }
end

I guess you didn't read the part were he provided this solution and commented on its shortcomings.

Yes I very much did not ;-)

At the end of the page he does finally make a decent Y combinator. Once again I didn't read it to the end and made my own. Here is an anonymous recursive function for you with an embedded Y combinator

proc { |x,*args| x.call(x,*args) }.call(proc { |x,n| if (n == 0) then 1 else n*x.call(x,n-1) end },5)

I guess they decided they would splash out and add the two extra lines ;)

libraries/base/Data/Function.hs

fix :: (a -> a) -> a
fix f = let x = f x in x

That's quite a nice way to define it.

At the meeting we were running through the standard library and trying to find idiomatic uses of the functions it in.

The main thing that puzzled me is that the type of fix is

fix :: (a -> a) -> a

but "a" must in fact have type
	b -> b
because it's used as a function.





Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links