Skip to content

Commit 271dde9

Browse files
committed
value: display left and rights as L(x) and R(x); drop DispUnlessUnit
Previously we would display left branches as 0 and right branches as 1, and had a special case where if the child node was unit, we would not display the inner (ε) to reduce noise. Now that we special-case all bitstrings, in particular bitstrings of length 1, this special-case is unnecessary and actually confusing. Now if we encounter a sum type we know it's *not* a bit and it would be clearer to indicate it as L or R, and if the child is a unit, we should unconditionally display that.
1 parent 6c88a8c commit 271dde9

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

src/value.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -759,29 +759,24 @@ impl fmt::Display for Value {
759759
// that we handle products more explicitly.
760760
enum S<'v> {
761761
Disp(ValueRef<'v>),
762-
DispUnlessUnit(ValueRef<'v>),
763762
DispCh(char),
764763
}
765764

766765
let mut stack = Vec::with_capacity(1024);
767-
// Next node to visit, and a boolean indicating whether we should
768-
// display units explicitly (turned off for sums, since a sum of
769-
// a unit is displayed simply as 0 or 1.
766+
// Next node to visit.
770767
stack.push(S::Disp(self.as_ref()));
771768

772769
'main_loop: while let Some(next) = stack.pop() {
773770
let value = match next {
774-
S::Disp(ref value) | S::DispUnlessUnit(ref value) => value,
771+
S::Disp(ref value) => value,
775772
S::DispCh(ch) => {
776773
write!(f, "{}", ch)?;
777774
continue;
778775
}
779776
};
780777

781778
if value.is_unit() {
782-
if !matches!(next, S::DispUnlessUnit(..)) {
783-
f.write_str("ε")?;
784-
}
779+
f.write_str("ε")?;
785780
} else {
786781
// First, write any bitstrings out
787782
for tmr in &Tmr::TWO_TWO_N {
@@ -812,11 +807,13 @@ impl fmt::Display for Value {
812807

813808
// If we don't have a bitstring, then write out the explicit value.
814809
if let Some(l_value) = value.as_left() {
815-
f.write_str("0")?;
816-
stack.push(S::DispUnlessUnit(l_value));
810+
f.write_str("L(")?;
811+
stack.push(S::DispCh(')'));
812+
stack.push(S::Disp(l_value));
817813
} else if let Some(r_value) = value.as_right() {
818-
f.write_str("1")?;
819-
stack.push(S::DispUnlessUnit(r_value));
814+
f.write_str("R(")?;
815+
stack.push(S::DispCh(')'));
816+
stack.push(S::Disp(r_value));
820817
} else if let Some((l_value, r_value)) = value.as_product() {
821818
stack.push(S::DispCh(')'));
822819
stack.push(S::Disp(r_value));

0 commit comments

Comments
 (0)