Skip to content

Commit

Permalink
Types: Replace split with split_{sum, product}
Browse files Browse the repository at this point in the history
These methods are more precise and make the code more readable.
  • Loading branch information
uncomputable committed Nov 26, 2023
1 parent 6b46ce7 commit 10b63db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/merkle/amr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Amr {
/// Produce a CMR for an injl combinator
pub fn injl(ty: &FinalArrow, child: Amr) -> Self {
let a = &ty.source;
let (b, c) = ty.target.split().unwrap();
let (b, c) = ty.target.split_sum().unwrap();
Self::INJL_IV
.update(a.tmr().into(), b.tmr().into())
.update(c.tmr().into(), child)
Expand All @@ -69,15 +69,15 @@ impl Amr {
/// Produce a CMR for an injr combinator
pub fn injr(ty: &FinalArrow, child: Amr) -> Self {
let a = &ty.source;
let (b, c) = ty.target.split().unwrap();
let (b, c) = ty.target.split_sum().unwrap();
Self::INJR_IV
.update(a.tmr().into(), b.tmr().into())
.update(c.tmr().into(), child)
}

/// Produce a CMR for a take combinator
pub fn take(ty: &FinalArrow, child: Amr) -> Self {
let (a, b) = ty.source.split().unwrap();
let (a, b) = ty.source.split_product().unwrap();
let c = &ty.target;
Self::TAKE_IV
.update(a.tmr().into(), b.tmr().into())
Expand All @@ -86,7 +86,7 @@ impl Amr {

/// Produce a CMR for a drop combinator
pub fn drop(ty: &FinalArrow, child: Amr) -> Self {
let (a, b) = ty.source.split().unwrap();
let (a, b) = ty.source.split_product().unwrap();
let c = &ty.target;
Self::DROP_IV
.update(a.tmr().into(), b.tmr().into())
Expand All @@ -105,8 +105,8 @@ impl Amr {
}

fn case_helper(iv: Amr, ty: &FinalArrow, left: Amr, right: Amr) -> Self {
let (sum_a_b, c) = ty.source.split().unwrap();
let (a, b) = sum_a_b.split().unwrap();
let (sum_a_b, c) = ty.source.split_product().unwrap();
let (a, b) = sum_a_b.split_sum().unwrap();
let d = &ty.target;
iv.update(a.tmr().into(), b.tmr().into())
.update(c.tmr().into(), d.tmr().into())
Expand Down Expand Up @@ -148,7 +148,7 @@ impl Amr {
/// Produce a CMR for a disconnect combinator
pub fn disconnect(ty: &FinalArrow, right_arrow: &FinalArrow, left: Amr, right: Amr) -> Self {
let a = &ty.source;
let (b, d) = ty.target.split().unwrap();
let (b, d) = ty.target.split_product().unwrap();
let c = &right_arrow.source;
Self::DISCONNECT_IV
.update(a.tmr().into(), b.tmr().into())
Expand Down
10 changes: 0 additions & 10 deletions src/types/final_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,6 @@ impl Final {
self.bound == CompleteBound::Unit
}

/// Accessor for both children of the type, if they exist.
pub fn split(&self) -> Option<(Arc<Self>, Arc<Self>)> {
match &self.bound {
CompleteBound::Unit => None,
CompleteBound::Sum(left, right) | CompleteBound::Product(left, right) => {
Some((Arc::clone(left), Arc::clone(right)))
}
}
}

/// Return both children, if the type is a sum type
pub fn split_sum(&self) -> Option<(Arc<Self>, Arc<Self>)> {
match &self.bound {
Expand Down

0 comments on commit 10b63db

Please sign in to comment.