Created
February 6, 2025 04:57
-
-
Save ClarkeRemy/d579486a800ff3580508dee56c0ff6d4 to your computer and use it in GitHub Desktop.
looking into fixpoint combinator in rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://docs.rs/rust2fun/latest/src/rust2fun/combinator.rs.html#399-417 | |
trait Rec<T, R> { | |
fn apply(&self, x: T) -> R; | |
} | |
impl<T, R, F> Rec<T, R> for F | |
where | |
F: Fn(&dyn Rec<T, R>, T) -> R, | |
{ | |
fn apply(&self, x: T) -> R { | |
self(self, x) | |
} | |
} | |
pub fn fix<T, R, F>(f: F, x: T) -> R | |
where | |
F: Fn(&dyn Fn(T) -> R, T) -> R, | |
{ | |
(|rec: &dyn Rec<T, R>, y| f(&|z| rec.apply(z), y)).apply(x) | |
} | |
const NONE : fn(())->() = |()| fix::<_,(),_>(|none : &dyn Fn(())->() , ()| none(()), ()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment