fn main() {
println!("=== DeepCausality HKT: Adjunction Pattern ===\n");
println!("--- Reader/Writer Duality ---");
println!("(Demonstration of concept)");
let fetch_data = |cfg: Config, id: i32| -> String {
format!("Data for ID {} using Key {}", id, cfg.api_key)
};
let id_to_fetch = 42;
let reader = move |cfg: Config| fetch_data(cfg, id_to_fetch);
let my_config = Config {
api_key: "SECRET_KEY".to_string(),
};
let result = reader(my_config);
println!("Adjunction Result: {}", result);
}
struct Config {
api_key: String,
}
#[allow(dead_code)]
struct ConfigAdjunction;
#[allow(dead_code)]
impl ConfigAdjunction {
fn left_adjunct<A, B, F>(f: F) -> impl Fn(A) -> Box<dyn Fn(Config) -> B>
where
A: Clone + 'static,
F: Fn(Config, A) -> B + Clone + 'static,
{
move |a: A| {
let f = f.clone();
let a = a.clone();
Box::new(move |cfg: Config| f(cfg, a.clone()))
}
}
fn right_adjunct<A, B, F>(f: F) -> impl Fn(Config, A) -> B
where
F: Fn(A) -> Box<dyn Fn(Config) -> B>,
{
move |cfg: Config, a: A| {
let reader = f(a);
reader(cfg)
}
}
}