Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
d-plaindoux committed Sep 15, 2023
1 parent 2c51b7a commit 5fa3edd
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/core/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::core::hkp::HKP;
pub trait Transform<'a, A>: HKP<'a> {
type This: HKP<'a>;

fn from_hkp<B>(a: <Self::This as HKP<'a>>::T<B>) -> Self::T<B>;
fn hkp_to_self<B>(a: <Self::This as HKP<'a>>::T<B>) -> Self::T<B>;

fn from_self<B>(a: Self::T<B>) -> <Self::This as HKP<'a>>::T<B>;
fn self_to_hkp<B>(a: Self::T<B>) -> <Self::This as HKP<'a>>::T<B>;

fn to_hkp(self) -> <Self::This as HKP<'a>>::T<A>;
}
7 changes: 5 additions & 2 deletions src/specs/applicative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub mod infix {
type TL<B: 'a>: Applicative<'a, B>;

fn pure<B>(a: B) -> Self::T<B> {
Self::from_hkp(Self::This::pure(a))
Self::hkp_to_self(Self::This::pure(a))
}

fn apply<B, MAP>(self, mf: Self::T<MAP>) -> Self::T<B>
Expand All @@ -29,7 +29,10 @@ pub mod infix {
MAP: Fn(A) -> B,
Self: Sized,
{
Self::from_hkp(Self::This::apply(Self::from_self::<MAP>(mf), self.to_hkp()))
Self::hkp_to_self(Self::This::apply(
Self::self_to_hkp::<MAP>(mf),
self.to_hkp(),
))
}
}
}
8 changes: 4 additions & 4 deletions src/specs/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub mod infix {
type TL<B: 'a>: Bind<'a, B>;

fn join<B>(mma: Self::T<Self::T<B>>) -> Self::T<B> {
Self::from_hkp(Self::This::bind(Self::from_self(mma), |a| {
Self::from_self::<B>(a)
Self::hkp_to_self(Self::This::bind(Self::self_to_hkp(mma), |a| {
Self::self_to_hkp::<B>(a)
}))
}

Expand All @@ -33,8 +33,8 @@ pub mod infix {
BIND: Fn(A) -> Self::T<B> + 'a,
Self: Sized,
{
Self::from_hkp(Self::This::bind(self.to_hkp(), move |a| {
Self::from_self::<B>(mf(a))
Self::hkp_to_self(Self::This::bind(self.to_hkp(), move |a| {
Self::self_to_hkp::<B>(mf(a))
}))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/specs/functor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod infix {
MAP: Fn(A) -> B + 'a,
Self: Sized,
{
Self::from_hkp(Self::This::map(f, self.to_hkp()))
Self::hkp_to_self(Self::This::map(f, self.to_hkp()))
}
}
}
10 changes: 5 additions & 5 deletions src/specs/monad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ pub mod infix {
type TL<B: 'a>: Monad<'a, B>;

fn returns<B>(b: B) -> Self::T<B> {
Self::from_hkp(Self::This::returns(b))
Self::hkp_to_self(Self::This::returns(b))
}

fn join<B>(mma: Self::T<Self::T<B>>) -> Self::T<B> {
Self::from_hkp(<Self::This as Bind>::bind(Self::from_self(mma), |a| {
Self::from_self::<B>(a)
Self::hkp_to_self(<Self::This as Bind>::bind(Self::self_to_hkp(mma), |a| {
Self::self_to_hkp::<B>(a)
}))
}

Expand All @@ -31,8 +31,8 @@ pub mod infix {
BIND: Fn(A) -> Self::T<B> + 'a,
Self: Sized,
{
Self::from_hkp(<Self::This as Bind>::bind(self.to_hkp(), move |a| {
Self::from_self::<B>(mf(a))
Self::hkp_to_self(<Self::This as Bind>::bind(self.to_hkp(), move |a| {
Self::self_to_hkp::<B>(mf(a))
}))
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/standard/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ mod infix {
impl<'a, L, R: 'a> Transform<'a, R> for Either<L, R> {
type This = EitherK<L>;

fn from_hkp<B: 'a>(a: <Self::This as HKP<'a>>::T<B>) -> Self::T<B> {
fn hkp_to_self<B: 'a>(a: <Self::This as HKP<'a>>::T<B>) -> Self::T<B> {
a
}

fn from_self<B: 'a>(a: Self::T<B>) -> <Self::This as HKP<'a>>::T<B> {
fn self_to_hkp<B: 'a>(a: Self::T<B>) -> <Self::This as HKP<'a>>::T<B> {
a
}

Expand Down
4 changes: 2 additions & 2 deletions src/standard/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ pub mod infix {
impl<'a, A: 'a> Transform<'a, A> for Identity<A> {
type This = IdentityK;

fn from_hkp<B: 'a>(a: <Self::This as HKP<'a>>::T<B>) -> Self::T<B> {
fn hkp_to_self<B: 'a>(a: <Self::This as HKP<'a>>::T<B>) -> Self::T<B> {
a
}

fn from_self<B: 'a>(a: Self::T<B>) -> <Self::This as HKP<'a>>::T<B> {
fn self_to_hkp<B: 'a>(a: Self::T<B>) -> <Self::This as HKP<'a>>::T<B> {
a
}

Expand Down
4 changes: 2 additions & 2 deletions src/standard/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ pub mod infix {
impl<'a, A: 'a> Transform<'a, A> for Option<A> {
type This = OptionK;

fn from_hkp<B: 'a>(a: <Self::This as HKP<'a>>::T<B>) -> Self::T<B> {
fn hkp_to_self<B: 'a>(a: <Self::This as HKP<'a>>::T<B>) -> Self::T<B> {
a
}

fn from_self<B: 'a>(a: Self::T<B>) -> <Self::This as HKP<'a>>::T<B> {
fn self_to_hkp<B: 'a>(a: Self::T<B>) -> <Self::This as HKP<'a>>::T<B> {
a
}

Expand Down
4 changes: 2 additions & 2 deletions src/standard/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ mod infix {
impl<'a, A: 'a, E> Transform<'a, A> for Result<A, E> {
type This = ResultK<E>;

fn from_hkp<B: 'a>(a: <Self::This as HKP<'a>>::T<B>) -> Self::T<B> {
fn hkp_to_self<B: 'a>(a: <Self::This as HKP<'a>>::T<B>) -> Self::T<B> {
a
}

fn from_self<B: 'a>(a: Self::T<B>) -> <Self::This as HKP<'a>>::T<B> {
fn self_to_hkp<B: 'a>(a: Self::T<B>) -> <Self::This as HKP<'a>>::T<B> {
a
}

Expand Down
4 changes: 2 additions & 2 deletions src/standard/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ pub mod infix {
impl<'a, A: 'a> Transform<'a, A> for Vec<A> {
type This = VecK;

fn from_hkp<B: 'a>(a: <Self::This as HKP<'a>>::T<B>) -> Self::T<B> {
fn hkp_to_self<B: 'a>(a: <Self::This as HKP<'a>>::T<B>) -> Self::T<B> {
a
}

fn from_self<B: 'a>(a: Self::T<B>) -> <Self::This as HKP<'a>>::T<B> {
fn self_to_hkp<B: 'a>(a: Self::T<B>) -> <Self::This as HKP<'a>>::T<B> {
a
}

Expand Down

0 comments on commit 5fa3edd

Please sign in to comment.