fp_core/
hkt.rs

1use std::collections::HashMap;
2
3// TODO: use a declarative macro (see https://github.com/rust-lang/rust/issues/39412) to make this
4// one macro that is invoked repeatedly.
5
6pub trait HKT<U> {
7    type Current;
8    type Target;
9}
10
11macro_rules! derive_hkt {
12    ($t: ident) => {
13        impl<T, U> HKT<U> for $t<T> {
14            type Current = T;
15            type Target = $t<U>;
16        }
17    };
18}
19
20derive_hkt!(Option);
21derive_hkt!(Vec);
22
23impl<T, U, E> HKT<U> for Result<T, E> {
24    type Current = T;
25    type Target = Result<U, E>;
26}
27
28pub trait HKT3<U1, U2> {
29    type Current1;
30    type Current2;
31    type Target;
32}
33
34macro_rules! derive_hkt3 {
35    ($t:ident) => {
36        impl<T1, T2, U1, U2> HKT3<U1, U2> for $t<T1, T2> {
37            // The currently contained types
38            type Current1 = T1;
39            type Current2 = T2;
40            // How the U's get filled in.
41            type Target = $t<U1, U2>;
42        }
43    };
44}
45
46derive_hkt3!(HashMap);