Anonymous user
Y combinator: Difference between revisions
→{{header|Ursala}}
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
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
<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}}
|