Y combinator: Difference between revisions

m (→‎{{header|OCaml}}: duplicate)
Line 738:
<math>f = h(f)</math>, where <math>h(f)</math> is just the body of the
function with recursive calls to <math>f</math> in it. With a fixed point
combinator such as <code>my_fix</code> as defined above, you do almost the same thing, except it's <math>f =</math><code>my_fix
"f".</code> <math>h</math><code>("f")</code>, where the dot represents lambda abstraction and the
quotes signify a dummy variable. Using this
Line 749:
this,
<lang Ursala>#fix my_fix</lang>
where anythe user definedspecifies the function canto be used in place of <code>my_fix</code>.
Having done that, you may express recursive functions per convention by circular definitions,
as in this example of a Fibonacci function.
Line 769:
<1,2,6,24,120,720,5040,40320>,
<1,2,3,5,8,13,21,34>)</pre>
The fixed point combinator defined above is theoretically correct but inefficient and limited to first order functions, whereas the standard distribution includes a library containing(<code>sol</code>) providing a hierarchy of fixed point combinators suitable for production use and with higher order functions. A more efficient alternative implementation of <code>my_fix</code> would be <code>general_function_fixer 0</code> (with 0 signifying the lowest order of fixed point combinators), or if that's too easy, then by this definition.
<lang Ursala>#import sol
 
#fix general_function_fixer 1
 
my_fix "f" = "f" my_fix "f"</lang>
Note that this equation is solved using the next fixed point combinator in the hierarchy.
 
{{omit from|C}}
Anonymous user