diff --git a/.gitignore b/.gitignore deleted file mode 100644 index ea8c4bf..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index b69769b..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "generic" -version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index c1c4ae5..0000000 --- a/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "generic" -version = "0.1.0" -edition = "2021" - -[dependencies] diff --git a/src/example.rs b/src/example.rs deleted file mode 100644 index 8b92e11..0000000 --- a/src/example.rs +++ /dev/null @@ -1,28 +0,0 @@ -use crate::generic::{Field, Sum, Generic}; - - -struct IntPair { - a: i32, - b: i32 -} - -impl Generic for IntPair { - type Representation = Sum, Field>; - fn generalize(self) -> Self::Representation { - Sum { - left: Field { value: self.a }, - right: Field { value: self.b } - } - } - fn specialize(rep: Self::Representation) -> Self { - let Sum { - left: Field { value: a }, - right: Field { value: b }, - } = rep; - IntPair { a, b } - } -} - -fn convert(x: IntPair) -> (i32, i32) { - Generic::specialize(x.generalize()) -} diff --git a/src/generic.rs b/src/generic.rs deleted file mode 100644 index c12c299..0000000 --- a/src/generic.rs +++ /dev/null @@ -1,31 +0,0 @@ -pub struct Sum where Con: IsConType, Rhs: IsRepType { - pub left: Con, - pub right: Rhs, -} - -pub struct Product where Rhs: IsConType { - pub left: Field, - pub right: Rhs -} - -pub struct Field { - pub value: T -} - -// types used for generic representation -pub trait IsRepType {} -impl IsRepType for Sum {} -impl IsRepType for Product {} -impl IsRepType for Field {} - -// types that represent constructors -pub trait IsConType {} -impl IsConType for Product {} -impl IsConType for Field {} - - -pub trait Generic { - type Representation: IsRepType; - fn generalize(self) -> Self::Representation; - fn specialize(rep: Self::Representation) -> Self; -} diff --git a/src/instances.rs b/src/instances.rs deleted file mode 100644 index f470fd1..0000000 --- a/src/instances.rs +++ /dev/null @@ -1,21 +0,0 @@ -use crate::generic::{Field, Generic, Sum}; - -impl Generic for (A, B) { - type Representation = Sum, Field>; - - fn generalize(self) -> Self::Representation { - let (l, r) = self; - Sum { - left: Field { value: l }, - right: Field { value: r } - } - } - - fn specialize(rep: Self::Representation) -> Self { - let Sum { - left: Field { value: a }, - right: Field { value: b }, - } = rep; - (a, b) - } -} diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index dc859d7..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,18 +0,0 @@ -pub mod generic; -mod example; -pub mod instances; - -pub fn add(left: u64, right: u64) -> u64 { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -}