Y combinator: Difference between revisions

m
→‎{{header|Rust}}: Fix deprecated trait object (needs explicit dyn)
m (Update Rust version. Rust 2018 removed anonymous parameters, so the original version doesn't build.)
m (→‎{{header|Rust}}: Fix deprecated trait object (needs explicit dyn))
Line 4,373:
// write the following:
 
fn y<T,R>(f:impl Fn(&dyn Fn(T) -> R, T) -> R) -> impl Fn(T) -> R {
move |t| (
|x: &Apply<T,R>, y| x.apply(x, y)
Line 4,398:
 
fn fac(n: usize) -> usize {
let almost_fac = |f: &dyn Fn(usize) -> usize, x|
if x == 0 {
1
Line 4,410:
 
fn fib( n: usize ) -> usize {
let almost_fib = |f: &dyn Fn(usize) -> usize, x|
if x < 2 {
1
Line 4,421:
 
fn optimal_fib( n: usize ) -> usize {
let almost_fib = |f: &dyn Fn((usize,usize,usize)) -> usize, (i0,i1,x)|
match x {
0 => i0,
Anonymous user