mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Simplify arity and branching calculation
This commit is contained in:
parent
0706615d29
commit
27b9dd8253
3 changed files with 46 additions and 81 deletions
|
@ -102,22 +102,19 @@ impl ListArity {
|
|||
|
||||
/// Could this list pattern include list pattern arity `other`?
|
||||
fn covers_arities_of(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(ListArity::Exact(l), ListArity::Exact(r)) => l == r,
|
||||
(ListArity::Exact(this_exact), ListArity::Slice(other_left, other_right)) => {
|
||||
// [_, _, _] can only cover [_, _, .., _]
|
||||
*this_exact == (other_left + other_right)
|
||||
self.covers_length(other.min_len())
|
||||
}
|
||||
|
||||
pub fn covers_length(&self, length: usize) -> bool {
|
||||
match self {
|
||||
ListArity::Exact(l) => {
|
||||
// [_, _, _] can only cover [_, _, _]
|
||||
*l == length
|
||||
}
|
||||
(ListArity::Slice(this_left, this_right), ListArity::Exact(other_exact)) => {
|
||||
// [_, _, .., _] can cover [_, _, _], [_, _, _, _], [_, _, _, _, _], and so on
|
||||
(this_left + this_right) <= *other_exact
|
||||
}
|
||||
(
|
||||
ListArity::Slice(this_left, this_right),
|
||||
ListArity::Slice(other_left, other_right),
|
||||
) => {
|
||||
// [_, _, .., _] can cover [_, _, .., _], [_, .., _, _], [_, _, .., _, _], [_, _, _, .., _, _], and so on
|
||||
(this_left + this_right) <= (other_left + other_right)
|
||||
ListArity::Slice(head, tail) => {
|
||||
// [_, _, .., _] can cover infinite arities >=3 , including
|
||||
// [_, _, .., _], [_, .., _, _], [_, _, .., _, _], [_, _, _, .., _, _], and so on
|
||||
head + tail <= length
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue