Skip to content

Commit d678ede

Browse files
committed
use Cons for Wcs too
It's clearer to read
1 parent 6d671d2 commit d678ede

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

crates/formality-core/src/collections.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ tuple_upcast!(Vec: A, B, C, D);
156156
/// where `head` will be the first item in the collection
157157
/// and tail will be a collection with the remaining items.
158158
/// Both can also be downcast to `()` which matches an empty collection.
159+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
159160
pub struct Cons<T, C>(pub T, pub C);
160161

161162
impl<T> DowncastTo<Cons<T, Set<T>>> for Set<T>

crates/formality-core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub mod variable;
3737
pub mod visit;
3838

3939
pub use cast::{Downcast, DowncastFrom, DowncastTo, Downcasted, To, Upcast, UpcastFrom, Upcasted};
40+
pub use collections::Cons;
4041
pub use collections::Deduplicate;
4142
pub use collections::Map;
4243
pub use collections::Set;

crates/formality-prove/src/prove/prove_wc_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use formality_core::judgment_fn;
1+
use formality_core::{judgment_fn, Cons};
22
use formality_types::grammar::Wcs;
33

44
use crate::{
@@ -28,7 +28,7 @@ judgment_fn! {
2828
(prove_wc(&decls, env, &assumptions, wc0) => c)
2929
(prove_after(&decls, c, &assumptions, &wcs1) => c)
3030
--- ("some")
31-
(prove_wc_list(decls, env, assumptions, (wc0, wcs1)) => c)
31+
(prove_wc_list(decls, env, assumptions, Cons(wc0, wcs1)) => c)
3232
)
3333
}
3434
}

crates/formality-types/src/grammar/wc.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::Arc;
22

33
use formality_core::{
4-
cast_impl, set, term, DowncastFrom, DowncastTo, Set, SetExt, Upcast, UpcastFrom, Upcasted,
4+
cast_impl, set, term, Cons, DowncastFrom, DowncastTo, Set, Upcast, UpcastFrom, Upcasted,
55
};
66

77
use crate::grammar::PR;
@@ -83,14 +83,10 @@ tuple_upcast!(A, B);
8383
tuple_upcast!(A, B, C);
8484
tuple_upcast!(A, B, C, D);
8585

86-
impl DowncastTo<(Wc, Wcs)> for Wcs {
87-
fn downcast_to(&self) -> Option<(Wc, Wcs)> {
88-
if self.set.is_empty() {
89-
None
90-
} else {
91-
let (wc, set) = self.set.clone().split_first().unwrap();
92-
Some((wc, set.upcast()))
93-
}
86+
impl DowncastTo<Cons<Wc, Wcs>> for Wcs {
87+
fn downcast_to(&self) -> Option<Cons<Wc, Wcs>> {
88+
let Cons(wc, set) = self.set.downcast_to()?;
89+
Some(Cons(wc, set.upcast()))
9490
}
9591
}
9692

0 commit comments

Comments
 (0)