From: Ian Jackson Date: Thu, 20 Apr 2023 16:10:32 +0000 (+0100) Subject: not working X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=86bb94e37315f1808fba7e605b19099a7154d014;p=rust-experiments.git not working --- diff --git a/src/main.rs b/src/main.rs index 3b6259c..966cf04 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,15 +3,15 @@ use std::sync::*; pub trait Callable: Any { type Output; - fn callable_call(self, a: Args) -> Self::Output; + fn curry_fn() -> fn(Self, Args) -> Self::Output; } impl Callable<(A,)> for F where F: Fn(A) -> O + 'static { type Output = O; - fn callable_call(self, (a,): (A,)) -> O { (self)(a) } + fn curry_fn() -> fn(Self, (A,)) -> O { |self_, (a,)| (self_)(a) } } impl Callable<(A,B)> for F where F: Fn(A,B) -> O + 'static { type Output = O; - fn callable_call(self, (a,b): (A,B)) -> O { (self)(a,b) } + fn curry_fn() -> fn(Self, (A,B)) -> O { |self_, (a,b)| (self_)(a,b) } } pub trait Object: Any + Send + Sync {} @@ -20,13 +20,17 @@ pub trait MI: Any { fn o_ti(&self) -> TypeId { TypeId::of::() } fn call(&self, o: Arc, u: ()) -> usize; } -/* -impl MI for fn(Arc) -> usize { - fn o_ti(&self) -> TypeId { TypeId::of::() } - fn call(&self, o: Arc) -> usize { - (self)(Arc::downcast(o).unwrap()) + +impl MI for fn((Arc,())) -> usize { + fn call(&self, o: Arc, u: ()) -> usize { + (self)((Arc::downcast(o).unwrap(), u)) } -}*/ +} +impl MI for fn((Arc,)) -> usize { + fn call(&self, o: Arc, _u: ()) -> usize { + (self)((Arc::downcast(o).unwrap(),)) + } +} fn example(o: Arc) -> usize { o.len() } @@ -61,11 +65,13 @@ where C: Fn((O,)) -> usize } */ fn main() { - const CL: () = { - |t| Callable::callable_call(example, t); - () + const CL: &dyn Any = { + &( + (&|t| Callable::curry_fn()(example, t)) + as fn(_) -> _ + ) }; -//example.callable_call(); +//example.curry_fn(); // let v: &dyn MI = k(example); println!("Hello, world!");