Skip to content

Commit

Permalink
Generalize Apps
Browse files Browse the repository at this point in the history
Previsouly `Apps` unapplies the tree of form `App(App(App(id: Ident, p1), p2), p3)` to `Apps(id: Ident, p1 :: p2 :: p3 :: Nil)`. Now it unapplies this as well but also `App(App(App(tree: Tree, p1), p2), p3)` to `Apps(tree: Tree, p1 :: p2 :: p3 :: Nil)`. This is especially useful for type parameters as we want to unwarp as many of layers of `App` as we can, then unwrap the `TyApp`.
  • Loading branch information
FlandiaYingman committed Oct 30, 2024
1 parent de0b196 commit 18499fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
7 changes: 2 additions & 5 deletions hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ extends Importer:
(ctx, acc)
newCtx.givenIn:
go(sts, newAcc)
case (hd @ LetLike(`let`, Apps(id, tups), rhso, N)) :: sts if id.name.headOption.exists(_.isLower) =>
case (hd @ LetLike(`let`, Apps(id: Ident, tups), rhso, N)) :: sts if id.name.headOption.exists(_.isLower) =>
val sym =
fieldOrVarSym(LetBind, id)
log(s"Processing `let` statement $id (${sym}) ${ctx.outer}")
Expand Down Expand Up @@ -428,12 +428,9 @@ extends Importer:
case S(t) => typeParams(t)
case N => (N, ctx)
// Add parameters to context
val (ps, newCtx) = td.params match
case S(ts) => // Go through all parameter lists
ts.foldLeft((Ls[Param](), newCtx1)):
val (ps, newCtx) = td.paramLists.foldLeft((Ls[Param](), newCtx1)):
case ((ps, ctx), t) => params(t)(using ctx).mapFirst(ps ++ _)
.mapFirst(some)
case N => (N, newCtx1)
val b = rhs.map(term(_)(using newCtx))
val r = FlowSymbol(s"‹result of ${sym}", nextUid)
val tdf = TermDefinition(k, sym, ps,
Expand Down
5 changes: 2 additions & 3 deletions hkmc2/shared/src/main/scala/hkmc2/syntax/Tree.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@ object PlainTup:
def apply(fields: Tree*): Tree = Tup(fields.toList)

object Apps:
def unapply(t: Tree): Opt[(Ident, Ls[Tup])] = t match
def unapply(t: Tree): Opt[(Tree, Ls[Tup])] = t match
case App(Apps(id, args), arg: Tup) => S(id, args :+ arg)
case id: Ident => S(id -> Nil)
case _ => N
case t => S(t, Nil)


sealed abstract class OuterKind(val desc: Str)
Expand Down

0 comments on commit 18499fc

Please sign in to comment.