Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][tlug] Re: Y Combinator
- Date: Fri, 06 Feb 2009 19:51:14 +0900
- From: John Fremlin <john@example.com>
- Subject: [tlug] Re: Y Combinator
- References: <20090129064805.GQ24024@smtp.office.cynic.net> <49867CF9.50006@bebear.net> <49893031.4000700@fremlin.org> <498BF621.1080608@bebear.net>
- User-agent: Thunderbird 2.0.0.19 (X11/20090103)
Edward Middleton wrote:John Fremlin wrote:Edward Middleton wrote:1. http://www.eecs.harvard.edu/~cduan/technical/ruby/ycombinator.shtmlIf 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.
- Follow-Ups:
- Re: [tlug] Re: Y Combinator
- From: tlug
- [tlug] Re: Y Combinator
- From: Stephen J. Turnbull
- References:
- Re: [tlug] Today's TSAC Meeting
- From: Edward Middleton
- [tlug] Re: Today's TSAC Meeting
- From: John Fremlin
- [tlug] Re: Y Combinator
- From: Edward Middleton
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] Disabling "Expire Messages" Function in KMail
- Next by Date: Re: [tlug] Disabling "Expire Messages" Function in KMail
- Previous by thread: [tlug] Re: Y Combinator
- Next by thread: Re: [tlug] Re: Y Combinator
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links