Talk:Fixed-point combinator: Difference between revisions

Content deleted Content added
m Replacing deprecated latex syntax mw:Extension:Math/Roadmap
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags
Line 103:
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.
 
<sourcesyntaxhighlight 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
</syntaxhighlight>
</source>
[[User:Subwy|Subwy]] ([[User talk:Subwy|talk]]) 10:58, 10 December 2008 (UTC)
 
Line 182:
There are two fix point combinators in Haskell, one is code-replicating, another is through sharing:
 
<sourcesyntaxhighlight lang="haskell">
fix f = f (fix f)
 
fix f = x where x = f x
</syntaxhighlight>
</source>
 
The second one lends itself naturally to corecursive definitions, like
 
<sourcesyntaxhighlight lang="haskell">
fibs = fix ((0:) . (1:) . next)
where
next (a:t@(b:_)) = (a+b):next t
</syntaxhighlight>
</source>
 
Used w/ the first fix, it still works though runs in quadratic time.
Line 217:
 
Here's a tested PHP 5.4 implementation for the Y Combinator function:
<sourcesyntaxhighlight lang=php>
function Y(callable $f)
{
Line 230:
return $funcA($funcA);
}
</syntaxhighlight>
</source>
 
And the factorial example applied to it:
<sourcesyntaxhighlight lang=php>
$factorial = Y(
function ($fac)
Line 249:
 
$result = $factorial(5); // 120
</syntaxhighlight>
</source>
 
[[User:Jazzer7|Jazzer7]] ([[User talk:Jazzer7|talk]]) 06:51, 6 June 2012 (UTC)
Line 505:
''For example, a Y-combinator implementation of factorial in the [[Wolfram Language]] would be''
 
<sourcesyntaxhighlight lang=ocaml>Y = Function[f, #[#]&[Function[g, f[g[g][##]&]]]];
factorial = Y[Function[f, If[# < 1, 1, # f[# - 1]] &]];
factorial[6] (*Yields 120*)</sourcesyntaxhighlight>
 
[[User:Thepigdog|Thepigdog]] ([[User talk:Thepigdog|talk]]) 02:20, 26 May 2015 (UTC)