Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TotalityCheck and tests #103

Merged
merged 8 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions core/src/main/scala/org/bykn/bosatsu/Pattern.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ object Pattern {
Pattern.PositionalStruct(name, ps)
}
}

/**
* Return the pattern with all the binding names removed
*/
def unbind: Pattern[N, T] =
pat match {
case Pattern.WildCard | Pattern.Literal(_) => pat
case Pattern.Var(_) => Pattern.WildCard
case Pattern.ListPat(items) =>
Pattern.ListPat(items.map {
case Left(_) => Left(None)
case Right(p) => Right(p.unbind)
})
case Pattern.Annotation(p, tpe) =>
Pattern.Annotation(p.unbind, tpe)
case Pattern.PositionalStruct(name, params) =>
Pattern.PositionalStruct(name, params.map(_.unbind))
}
}

case object WildCard extends Pattern[Nothing, Nothing]
Expand All @@ -61,6 +79,7 @@ object Pattern {
case class Annotation[N, T](pattern: Pattern[N, T], tpe: T) extends Pattern[N, T]
case class PositionalStruct[N, T](name: N, params: List[Pattern[N, T]]) extends Pattern[N, T]


implicit lazy val document: Document[Pattern[String, TypeRef]] =
Document.instance[Pattern[String, TypeRef]] {
case WildCard => Doc.char('_')
Expand Down
Loading