From 42d0f8100462f8a17a3ba1b86664310cdb71dfdc Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 6 Apr 2019 17:55:43 +0200 Subject: Rename some modules --- dhall/src/dhall_type.rs | 77 ------------------------------------------------- dhall/src/lib.rs | 6 ++-- dhall/src/traits.rs | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 80 deletions(-) delete mode 100644 dhall/src/dhall_type.rs create mode 100644 dhall/src/traits.rs (limited to 'dhall/src') diff --git a/dhall/src/dhall_type.rs b/dhall/src/dhall_type.rs deleted file mode 100644 index 64e07d9..0000000 --- a/dhall/src/dhall_type.rs +++ /dev/null @@ -1,77 +0,0 @@ -use dhall_core::*; -use dhall_generator::*; - -#[derive(Debug, Clone)] -pub enum ConversionError {} - -pub trait StaticType { - fn get_type() -> DhallExpr; - // fn as_dhall(&self) -> DhallExpr; - // fn from_dhall(e: DhallExpr) -> Result; -} - -impl StaticType for bool { - fn get_type() -> DhallExpr { - dhall_expr!(Bool) - } -} - -impl StaticType for Natural { - fn get_type() -> DhallExpr { - dhall_expr!(Natural) - } -} - -impl StaticType for Integer { - fn get_type() -> DhallExpr { - dhall_expr!(Integer) - } -} - -impl StaticType for String { - fn get_type() -> DhallExpr { - dhall_expr!(Text) - } -} - -impl StaticType for (A, B) { - fn get_type() -> DhallExpr { - let ta = A::get_type(); - let tb = B::get_type(); - dhall_expr!({ _1: ta, _2: tb }) - } -} - -impl StaticType for Option { - fn get_type() -> DhallExpr { - let t = T::get_type(); - dhall_expr!(Optional t) - } -} - -impl StaticType for Vec { - fn get_type() -> DhallExpr { - let t = T::get_type(); - dhall_expr!(List t) - } -} - -impl<'a, T: StaticType> StaticType for &'a T { - fn get_type() -> DhallExpr { - T::get_type() - } -} - -impl StaticType for std::marker::PhantomData { - fn get_type() -> DhallExpr { - dhall_expr!({}) - } -} - -impl StaticType for Result { - fn get_type() -> DhallExpr { - let tt = T::get_type(); - let te = E::get_type(); - dhall_expr!(< Ok: tt | Err: te>) - } -} diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index 5a155c8..7439312 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -10,14 +10,14 @@ mod normalize; pub use crate::normalize::*; pub mod binary; -mod dhall_type; pub mod imports; +mod traits; pub mod typecheck; -pub use crate::dhall_type::*; +pub use crate::imports::*; +pub use crate::traits::*; pub use dhall_generator::expr; pub use dhall_generator::subexpr; pub use dhall_generator::StaticType; -pub use crate::imports::*; // pub struct DhallExpr(dhall_core::DhallExpr); diff --git a/dhall/src/traits.rs b/dhall/src/traits.rs new file mode 100644 index 0000000..64e07d9 --- /dev/null +++ b/dhall/src/traits.rs @@ -0,0 +1,77 @@ +use dhall_core::*; +use dhall_generator::*; + +#[derive(Debug, Clone)] +pub enum ConversionError {} + +pub trait StaticType { + fn get_type() -> DhallExpr; + // fn as_dhall(&self) -> DhallExpr; + // fn from_dhall(e: DhallExpr) -> Result; +} + +impl StaticType for bool { + fn get_type() -> DhallExpr { + dhall_expr!(Bool) + } +} + +impl StaticType for Natural { + fn get_type() -> DhallExpr { + dhall_expr!(Natural) + } +} + +impl StaticType for Integer { + fn get_type() -> DhallExpr { + dhall_expr!(Integer) + } +} + +impl StaticType for String { + fn get_type() -> DhallExpr { + dhall_expr!(Text) + } +} + +impl StaticType for (A, B) { + fn get_type() -> DhallExpr { + let ta = A::get_type(); + let tb = B::get_type(); + dhall_expr!({ _1: ta, _2: tb }) + } +} + +impl StaticType for Option { + fn get_type() -> DhallExpr { + let t = T::get_type(); + dhall_expr!(Optional t) + } +} + +impl StaticType for Vec { + fn get_type() -> DhallExpr { + let t = T::get_type(); + dhall_expr!(List t) + } +} + +impl<'a, T: StaticType> StaticType for &'a T { + fn get_type() -> DhallExpr { + T::get_type() + } +} + +impl StaticType for std::marker::PhantomData { + fn get_type() -> DhallExpr { + dhall_expr!({}) + } +} + +impl StaticType for Result { + fn get_type() -> DhallExpr { + let tt = T::get_type(); + let te = E::get_type(); + dhall_expr!(< Ok: tt | Err: te>) + } +} -- cgit v1.2.3