import reorganized

This commit is contained in:
AF 2023-04-23 16:25:40 +00:00
parent 4afbdb81a5
commit c079fc3153
22 changed files with 52 additions and 109 deletions

3
rustfmt.toml Normal file
View File

@ -0,0 +1,3 @@
# imports_granularity = "Item"
# group_imports = "StdExternalCrate"
use_field_init_shorthand = true

View File

@ -10,17 +10,17 @@ mod serialization;
mod slice_deserializer;
mod typeless;
pub use addresses::*;
pub use hashing::*;
pub use resolution::*;
pub use serialization::*;
pub use slice_deserializer::*;
pub use typeless::*;
use std::{error::Error, fmt::Display, rc::Rc};
use crate::func::*;
pub use self::addresses::*;
pub use self::hashing::*;
pub use self::resolution::*;
pub use self::serialization::*;
pub use self::slice_deserializer::*;
pub use self::typeless::*;
pub trait Diagnostic<T: Monad> {
fn after<'a, A>(fa: T::F<'a, A>, event: &'a str) -> T::F<'a, A>;
fn before<'a, A>(fa: T::F<'a, A>, event: &'a str) -> T::F<'a, A>;

View File

@ -1,6 +1,6 @@
//! Useful helper functions/methods to extrapolate the existing behaviour.
use crate::func::*;
use super::*;
/// Equivalent of Haskell's `fmap`. `function-function` equivalent of [Functor::fmap].
pub fn fmap<'a, T: 'a + Functor, A: 'a, B: 'a>(

View File

@ -1,4 +1,5 @@
use super::{tests::*, *};
use super::tests::*;
use super::*;
pub trait FunctorTestSuite: WeakFunctor + Eqr {
fn sample<'a, A: 'a, F: FnMut(&'a dyn Fn(A) -> Self::F<'a, A>)>(f: F)

View File

@ -1,6 +1,9 @@
use std::{
fmt::Debug,
ops::{Add, AddAssign},
};
use super::*;
use core::fmt::Debug;
use std::ops::{Add, AddAssign};
pub struct TestResults {
success: usize,

View File

@ -3,5 +3,3 @@ pub mod func;
pub mod std;
#[cfg(test)]
mod testing;
#[cfg(test)]
mod xrcs;

View File

@ -7,7 +7,8 @@ pub mod plain;
use std::marker::PhantomData;
use crate::core::*;
use crate::std::*;
use super::*;
/// This trait combines functionality of [`Mentionable`] and [`Factory`],
/// while limiting [`Mentionable::points`] (and corresponding [`Mentionable::topology`]) to an empty sequence.

View File

@ -1,6 +1,6 @@
//! [`Plain`] type for storing raw byte sequnces.
use crate::std::atomic::*;
use super::*;
/// Raw bytes storage. Use [`Plain::raw`] to get the data.
///

View File

@ -5,9 +5,9 @@
use std::convert::identity;
use super::typeless::*;
use crate::core::*;
use crate::std::*;
use super::{typeless::*, *};
struct CastResolver<'a, Ctx: 'a + Context> {
points: Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>,

View File

@ -4,8 +4,7 @@ use std::error::Error;
use std::fmt::Display;
use crate::core::*;
use crate::std::inlining::static_pair::*;
use crate::std::inlining::*;
use crate::std::inlining::{static_pair::*, *};
#[derive(Clone)]
pub struct Pair<A, B> {

View File

@ -1,10 +1,7 @@
//! Basic implementation of a stack/linked list.
use crate::core::*;
use crate::std::inlining::*;
use crate::std::nullable::*;
use crate::std::point::*;
use crate::std::*;
use crate::std::{inlining::*, nullable::*, point::*, *};
/// Node containing a (nullable) reference to the next node and an element.
pub struct StackNode<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {

View File

@ -2,11 +2,13 @@
pub mod static_pair;
use super::atomic::atomic_object::*;
use super::atomic::*;
use super::point::*;
use crate::core::*;
use crate::std::*;
use super::{
atomic::{atomic_object::*, *},
point::*,
*,
};
/// This factory should return an error on EOF.
pub trait InlineableFactory {}

View File

@ -3,8 +3,9 @@
use std::ops::Deref;
use crate::std::*;
use super::*;
use crate::core::*;
/// Trait to represent serialisation of object's data.
/// Due to serialisation being [Context]-free in RADN,

View File

@ -1,7 +1,8 @@
use std::rc::Rc;
use crate::core::*;
use crate::func::*;
use super::*;
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
fn prepare_bytes_for_hashing(mentioned: &A) -> Vec<u8> {

View File

@ -1,9 +1,8 @@
//! This module introduces [`Option`]-like concepts into RADN typesystem using [`Nullable`].
use super::inlining::*;
use super::point::*;
use crate::core::*;
use crate::std::*;
use super::{inlining::*, point::*, *};
/// Nullable reference type. Made for use as a linking element in data structures.
pub enum Nullable<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {

View File

@ -1,8 +1,6 @@
//! Module responsible for making [Point]s [Mentionable].
use std::error::Error;
use std::fmt::Display;
use std::rc::Rc;
use std::{error::Error, fmt::Display, rc::Rc};
use crate::core::*;

View File

@ -2,9 +2,11 @@ mod trace;
mod traced;
use crate::core::*;
use crate::func::*;
use trace::*;
pub use traced::Traced;
use super::*;
use self::trace::*;
pub use self::traced::*;
pub struct TracedDiagnostic;

View File

@ -1,7 +1,8 @@
use std::rc::Rc;
use crate::core::*;
use crate::func::*;
use super::*;
struct WrappedOrigin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
w_factory: A::Fctr,

View File

@ -1,14 +1,13 @@
pub mod counted;
pub mod traced;
use std::error::Error;
use std::fmt::Display;
use std::rc::Rc;
use std::{error::Error, fmt::Display, rc::Rc};
use sha2::{Digest, Sha256};
use crate::core::*;
use crate::func::*;
use crate::std::cast::*;
use sha2::{Digest, Sha256};
pub struct NoDiagnostic;

View File

@ -1,9 +1,10 @@
use std::cmp::max;
use super::*;
use crate::core::*;
use crate::func::*;
use super::*;
pub struct TestContextCounted;
impl Context for TestContextCounted {

View File

@ -1,8 +1,9 @@
use super::*;
use crate::core::*;
use crate::func::*;
use crate::std::tracing::*;
use super::*;
pub struct TestContextTraced;
impl Context for TestContextTraced {

View File

@ -1,64 +0,0 @@
/// Solutions to some exercises by Alisa Feistel.
/// Included here for their relevance to the whole Monad theme.
/// Also, Alisa is too lazy to put them in a separate project for now.
#[cfg(test)]
mod tests {
fn bind<T, F: FnOnce(T) -> Option<T>>(f: F, fa: Option<T>) -> Option<T> {
match fa {
Some(a) => f(a),
None => None,
}
}
#[test]
fn test() {
assert_eq!(bind(|x: i32| Some(x + 3), Some(2)), Some(5));
assert_eq!(bind(|x: i32| Some(x + 3), None), None);
assert_eq!(bind(|_: i32| None, Some(2)), None);
assert_eq!(bind(|_: i32| None, None), None);
assert_eq!(bind(|x: &str| Some(x), Some("apple")), Some("apple"));
assert_eq!(
bind(|_: &str| Some("banana"), Some("apple")),
Some("banana")
);
let banana = "banana".to_string();
assert_eq!(
bind(|_: &str| Some(banana.as_str()), Some("apple")),
Some("banana")
);
let banana = "banana".to_string();
assert_eq!(
bind(|_: String| Some(banana), Some("apple".to_string())),
Some("banana".to_string())
);
}
}
#[cfg(test)]
mod reftests {
fn refbind<'a, 'b, T: 'a + ?Sized, F: 'a + Fn(&'a T) -> Option<&'b T>>(
f: F,
fa: Option<&'a T>,
) -> Option<&'b T> {
match fa {
Some(a) => f(a),
None => None,
}
}
#[test]
fn test() {
let apple = "apple".to_string();
let banana = "banana".to_string();
assert_eq!(
refbind(|_: &String| Some(&banana), Some(&apple)),
Some(&banana)
);
let banana = "banana";
assert_eq!(refbind(|_: &str| Some(banana), Some("apple")), Some(banana));
}
}