タグ

ブックマーク / gist.github.com/14427 (1)

  • Higher-kinded type trait

    hkt.rs P� ��U P� ��U use std::rc::Rc; trait HKT<U> { type C; // Current type type T; // Type with C swapped with U } macro_rules! derive_hkt { ($t:ident) => { impl<T, U> HKT<U> for $t<T> { type C = T; type T = $t<U>; } } } derive_hkt!(Vec); derive_hkt!(Option); derive_hkt!(Box); derive_hkt!(Rc); trait Functor<U>: HKT<U> { fn map<F>(&self, f: F) -> Self::T where F: Fn(&Self::C) -> U; } impl<T, U> F

    Higher-kinded type trait
    zyzy
    zyzy 2016/02/16
    Rustの擬似高階型だが、その手があったか!!
  • 1