Skip to content

Commit

Permalink
some minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek committed Sep 29, 2023
1 parent b7cc383 commit 30937b1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
16 changes: 0 additions & 16 deletions core/src/main/scala/org/bykn/bosatsu/ListUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,4 @@ private[bosatsu] object ListUtil {
if (bs eq as) nel
else NonEmptyList.fromListUnsafe(bs)
}

def find[X, Y](ls: NonEmptyList[X])(fn: X => Option[Y]): Option[Y] = {
@annotation.tailrec
def loop(head: X, tail: List[X]): Option[Y] = {
val h = fn(head)
if (h.isDefined) h
else {
tail match {
case Nil => None
case head :: next => loop(head, next)
}
}
}

loop(ls.head, ls.tail)
}
}
5 changes: 3 additions & 2 deletions core/src/main/scala/org/bykn/bosatsu/TypedExpr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,10 @@ object TypedExpr {
(left, right) match {
case (TyVar(v), right) if solveSet(v) =>
Some(state.updated(v, right))
case (ForAll(b, i), r) =>
case (fa @ ForAll(b, i), r) =>
if (fa.sameAs(r)) Some(state)
// this will mask solving for the inside values:
solve(i,
else solve(i,
r,
state,
solveSet -- b.toList.iterator.map(_._1),
Expand Down
19 changes: 11 additions & 8 deletions core/src/main/scala/org/bykn/bosatsu/TypedExprNormalization.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.bykn.bosatsu

import cats.Foldable
import cats.data.NonEmptyList
import cats.implicits._
import org.bykn.bosatsu.rankn.{Type, TypeEnv}

import Identifier.{Bindable, Constructor}

import cats.syntax.all._

object TypedExprNormalization {
import TypedExpr._

Expand Down Expand Up @@ -705,15 +707,16 @@ object TypedExprNormalization {
// $COVERAGE-ON$
}

ListUtil.find[Branch[A], TypedExpr[A]](m.branches) { case (p, r) =>
makeLet(p).map { names =>
val lit = Literal[A](li, Type.getTypeOf(li), m.tag)
// all these names are bound to the lit
names.distinct.foldLeft(r) { case (r, n) =>
Let(n, lit, r, RecursionKind.NonRecursive, m.tag)
Foldable[NonEmptyList]
.collectFirstSome[Branch[A], TypedExpr[A]](m.branches) { case (p, r) =>
makeLet(p).map { names =>
val lit = Literal[A](li, Type.getTypeOf(li), m.tag)
// all these names are bound to the lit
names.distinct.foldLeft(r) { case (r, n) =>
Let(n, lit, r, RecursionKind.NonRecursive, m.tag)
}
}
}
}
case EvalResult.Constant(Lit.Str(_)) =>
None
}
Expand Down

0 comments on commit 30937b1

Please sign in to comment.