Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use super::*;
- pub use value_struct::*;
- pub trait ListMap<S>: List {
- type Result<U: 'static>: List;
- }
- impl<S> ListMap<S> for Empty {
- type Result<U: 'static> = Self;
- }
- impl<S, T: 'static> ListMap<S> for TypedEmpty<T> {
- type Result<U: 'static> = TypedEmpty<U>;
- }
- impl<S> ListMap<S> for ListError {
- type Result<U: 'static> = Self;
- }
- impl<S, T: 'static> ListMap<S> for TypedListError<T> {
- type Result<U: 'static> = TypedListError<U>;
- }
- pub macro let_list_map {
- ($(type $name: ident = ($($t:tt)*)($L: ty);)*) => {
- $(
- let_list_map_sing! {
- type $name = ($($t)*)($L);
- }
- )*
- }
- }
- pub macro let_list_map_sing {
- (type $name: ident = (|$arg: ident| $x: expr)($L: ty);) => {
- pub struct H;
- forall_types! {
- all {
- type U #+ #T =
- type_of!(default_value!($L, ftype!(#T)));
- type T #+ #T =
- type_of!((&const |$arg: U #+ #T| $x)
- (default_value!($L, ftype!(#T))));
- pub const fn f #+ #T(x: ftype!(#T)) -> T #+ #T {
- (&const |$arg: U #+ #T| $x)(convert_value!($L, ftype!(#T), x))
- }
- impl<const T: ftype!(#T), N: ListMap<H>>
- ListMap<H> for ListNode<ftype!(#T), self::value_struct![#T,T], N>
- where as_value_spec![T #+ #T; {f #+ #T(T)}]: {
- type Result<U: 'static> =
- ListNode<
- T #+ #T,
- as_value_spec![T #+ #T; {f #+ #T(T)}],
- <N as ListMap<H>>::Result<T #+ #T>>;
- }
- }
- }
- type $name = <$L as ListMap<H>>::Result<()>;
- },
- (type $name: ident = (|_| $x: expr)($L: ty);) => {
- pub struct H;
- type T = type_of!((&const |_| $x)(0));
- #[allow(unused_braces)]
- pub const fn f(_: i32) -> T {
- $x
- }
- impl<S, E: Value<ValueType=S>, N: ListMap<H>>
- ListMap<H> for ListNode<S, E, N>
- where as_value_spec![T; {f(0)}]: {
- type Result<U: 'static> =
- ListNode<
- T,
- as_value_spec![T; {f(0)}],
- <N as ListMap<H>>::Result<T>>;
- }
- type $name = <$L as ListMap<H>>::Result<()>;
- },
- (type $name: ident = (|$arg: ident: $T: ty| $x: expr)($L: ty);) => {
- pub struct H;
- type T = type_of!((&const |$arg: ftype!($T)| $x)
- (default_value!($L, ftype!($T))));
- #[allow(unused_braces)]
- pub const fn f(x: ftype!($T)) -> T {
- (&const |$arg: ftype!($T)| -> T { $x } )(x)
- }
- impl<const V: ftype!($T), N: ListMap<H>>
- ListMap<H> for ListNode<ftype!($T), value_struct![$T, V], N>
- where as_value_spec![T; {f(V)}]: {
- type Result<U: 'static> =
- ListNode<
- T,
- as_value_spec![T; {f(V)}],
- <N as ListMap<H>>::Result<T>>;
- }
- type $name = <$L as ListMap<H>>::Result<()>;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement