
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tlug] Re: Today's TSAC Meeting
- Date: Wed, 04 Feb 2009 15:05:37 +0900
- From: John Fremlin <john@example.com>
- Subject: [tlug] Re: Today's TSAC Meeting
- References: <20090129064805.GQ24024@smtp.office.cynic.net> <49867CF9.50006@bebear.net>
- User-agent: Thunderbird 2.0.0.19 (X11/20090103)
Edward Middleton wrote:
Y-Combinators were discussed in this meeting and John Fremlin questioned
whether they they were useful for anything. Here[1] is an example using
the Y-Combinator[2] in ruby to implement autovivication in Ruby hashes
I am sure that there are real uses for the Y Combinator. It is important
in some more primitive languages. We were talking about Haskell which is
quite advanced.
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
hash = make_hash_func
# Now this will work:
hash['a']['b']['c']['d']['e']['f']['g'] = 1
# And hash looks like:
hash # => {"a"=>{"b"=>{"c"=>{"d"=>{"e"=>{"f"=>{"g"=>1}}}}}}}
I don't know much Ruby so please correct me if I am wrong.
2. http://en.wikipedia.org/wiki/Y_combinator
The Y Combinator is for making an anonymous recursive function.
I am sure that there are real uses for it. Can you provide an example in
Haskell? Seeing as it is part of the standard library one would hope
that it was at least occasionally used.
Home |
Main Index |
Thread Index