Mailing List Archive


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

[tlug] Re: Today's TSAC Meeting



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

Home Page Mailing List Linux and Japan TLUG Members Links