Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek committed Dec 11, 2023
1 parent 1dbc7d2 commit 8e7dcf9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion core/src/main/scala/org/bykn/bosatsu/rankn/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ object Type {
Quantification.fromLists(
forallList.filter { case (b, _) => fn(b) },
existList.filter { case (b, _) => fn(b) })

def existsQuant(fn: ((Var.Bound, Kind)) => Boolean): Boolean
}

object Quantification {
Expand All @@ -78,6 +80,9 @@ object Type {
case Exists(evars) => Dual(vars, evars)
case Dual(f, e) => Dual(vars ::: f, e)
}

def existsQuant(fn: ((Var.Bound, Kind)) => Boolean): Boolean =
vars.exists(fn)
}
case class Exists(vars: NonEmptyList[(Var.Bound, Kind)]) extends Quantification {
def existList: List[(Var.Bound, Kind)] = vars.toList
Expand All @@ -88,6 +93,9 @@ object Type {
case Exists(evars) => Exists(vars ::: evars)
case Dual(f, e) => Dual(f, vars ::: e)
}

def existsQuant(fn: ((Var.Bound, Kind)) => Boolean): Boolean =
vars.exists(fn)
}
case class Dual(
foralls: NonEmptyList[(Var.Bound, Kind)],
Expand All @@ -102,6 +110,9 @@ object Type {
case Exists(evars) => Dual(foralls, exists ::: evars)
case Dual(f, e) => Dual(foralls ::: f, exists ::: e)
}

def existsQuant(fn: ((Var.Bound, Kind)) => Boolean): Boolean =
foralls.exists(fn) || exists.exists(fn)
}

implicit val quantificationOrder: Order[Quantification] =
Expand Down Expand Up @@ -214,7 +225,7 @@ object Type {
}
else {
val freeBoundSet: Set[Var.Bound] = freeBound.toSet
val collisions = q.vars.exists { case (b, _) => freeBoundSet(b) }
val collisions = q.existsQuant { case (b, _) => freeBoundSet(b) }
if (!collisions) {
// we don't need to rename the vars
Quantified(q, applyAllRho(rho, args))
Expand Down

0 comments on commit 8e7dcf9

Please sign in to comment.