#![allow(unused)] mod equal { use core::marker::PhantomData; pub struct Equal(PhantomData<(Val1, Val2)>); use mononym::*; pub fn check_equal, Val2: HasType>( value1: &Named, value2: &Named, ) -> Option> { if value1.value() == value2.value() { Some(Equal(PhantomData)) } else { None } } } mod size { use core::marker::PhantomData; use mononym::*; use super::sort::{ Sorted, SortedFrom, }; exists! { ExistListSize(size: usize) => ListHasSize(list: Vec); } proof! { NonEmpty(list: Vec); } // pub struct ListSize(PhantomData<(ListVal, SizeVal)>); // pub struct NonEmpty(PhantomData); // pub struct SizeResult< // Elem, // ListVal: HasType>, // SizeVal: HasType, // > { // size: Named, // size_proof: ListSize, // non_empty_proof: Option>, // phantom: PhantomData, // } pub fn list_size>>( seed: Seed, list: &Named>, ) -> ExistListSize, Elem, ListVal> { let size = list.value().len(); new_exist_list_size(seed, size) } pub fn list_not_empty< Elem, ListVal: HasType>, SizeVal: HasType, >( list_size: &Named, _list_has_size: &ListHasSize, ) -> Option> { if list_size.value() == &0 { None } else { Some(NonEmpty::new()) } } pub fn sorted_preserve_size< Elem, OldListVal: HasType>, NewListVal: HasType>, SizeVal: HasType, >( _size: ListHasSize, _sorted: Sorted, _sorted_from: SortedFrom, ) -> ListHasSize { ListHasSize::new() } pub fn sorted_preserve_non_empty< Elem, OldListVal: HasType>, NewListVal: HasType>, >( _non_empty: NonEmpty, _sorted: Sorted, _sorted_from: SortedFrom, ) -> NonEmpty { NonEmpty(PhantomData) } } mod sort { use core::marker::PhantomData; use mononym::{ HasType, Name, Named, Seed, }; pub struct Sorted(PhantomData); pub struct SortedFrom( PhantomData<(NewListVal, OldListVal)>, ); pub struct SortedResult< Elem, OldListVal: HasType>, NewListVal: HasType>, > { new_list: Named>, sorted: Sorted, sorted_from: SortedFrom, } pub fn sort>>( seed: Seed, list: Named>, ) -> SortedResult>> where { let mut new_list = list.into_value(); new_list.sort(); let new_list = seed.new_named(new_list); SortedResult { new_list, sorted: Sorted(PhantomData), sorted_from: SortedFrom(PhantomData), } } pub unsafe fn sorted_axiom() -> Sorted { Sorted(PhantomData) } pub unsafe fn sorted_from_axiom( ) -> SortedFrom { SortedFrom(PhantomData) } } mod min { use core::marker::PhantomData; use mononym::{ HasType, Name, Named, Seed, }; use super::{ size::NonEmpty, sort::Sorted, }; pub struct MinElem(PhantomData<(ListVal, ElemVal)>); pub struct MinResult<'a, Elem, ListVal, ElemVal: HasType<&'a Elem>> { elem: Named, min_proof: MinElem, } pub fn min<'a, Elem, ListVal: HasType>>( seed: Seed, list: &'a Named>, _sorted: Sorted, _non_empty: NonEmpty, ) -> MinResult<'a, Elem, ListVal, impl HasType<&'a Elem>> { let elem = list.value().first().unwrap(); MinResult { elem: seed.new_named(elem), min_proof: MinElem(PhantomData), } } } mod lookup { use core::marker::PhantomData; use std::collections::BTreeMap; use mononym::{ HasType, Name, Named, Seed, }; pub struct HasKey( PhantomData<(MapVal, KeyVal, ValueVal)>, ); pub struct LookupResult< 'a, Value, MapVal, KeyVal, ValueVal: HasType<&'a Value>, > { enry_value: Named, has_key_proof: HasKey, } pub fn lookup< 'a, Key, Value, MapVal: HasType>, KeyVal: HasType, >( seed: Seed, map: &'a Named>, key: &Named, ) -> Option>> where Key: Ord, Value: Clone, { map.value().get(key.value()).map(move |value| { let value = seed.new_named(value); LookupResult { enry_value: value, has_key_proof: HasKey(PhantomData), } }) } } fn main() {}