Talk:Fixed-point combinator: Difference between revisions

Content deleted Content added
Subwy (talk | contribs)
Further examples: new section
Line 47:
 
:As is explained in the section [[Fixed point combinator#Existence of fixed point combinators]], fixed point combinators need not exist for all settings, and need not be [[total function|total]], i.e. they may diverge for some (even almost all) inputs. However, there are important settings such as '''CPO''', the [[cartesian closed category]] of [[complete partial order]]s with [[Scott continuity|Scott continuous]] maps, where fix points always exist. — [[User:Tobias Bergemann|Tobias Bergemann]] ([[User talk:Tobias Bergemann|talk]]) 12:25, 18 November 2008 (UTC)
 
== Further examples ==
 
Both examples for the Y combinator use functional languages, which support [[Currying]]. This means that the given examples can not simply be translated to other languages which support first-class functions, but no currying/partial exaluation.
 
Here is an example in Ruby of the y combinator and its use with factorial. It explicitly uses an additional function which takes the arguments for our original function, apart from that, it is a direct translation of the y combinator's definition.
Maybe we could try to improve it a little / make it more readable (at least add proper indendation) and then incorporate it into the article.
 
<source lang=ruby>
y = lambda { |f| (lambda { |x| lambda { |*args| (f.call(x.call(x))).call(*args) }}).call(lambda { |x| lambda { |*args| (f.call(x.call(x))).call(*args) }})}
b = y.call(lambda { |f| lambda {|i| if i == 0 then 1 else i * (f.call(i-1)) end }})
puts(b.call 5) # 120
</source>
[[User:Subwy|Subwy]] ([[User talk:Subwy|talk]]) 10:58, 10 December 2008 (UTC)