Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
term: lambda with implicit argument
Browse files Browse the repository at this point in the history
  • Loading branch information
HoshinoTented committed Jan 13, 2024
1 parent 4622634 commit 3895187
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions base/src/main/java/org/aya/syntax/core/term/LamTerm.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
package org.aya.syntax.core.term;

import kala.collection.SeqLike;
import kala.function.BooleanConsumer;
import kala.function.IndexedFunction;
import org.aya.syntax.ref.LocalVar;
import org.jetbrains.annotations.NotNull;

public record LamTerm(Term body) implements StableWHNF {
public record LamTerm(boolean explicit, Term body) implements StableWHNF {
public @NotNull LamTerm update(@NotNull Term body) {
return body == this.body
? this
: new LamTerm(body);
: new LamTerm(explicit, body);
}

@Override
public @NotNull Term descent(@NotNull IndexedFunction<Term, Term> f) {
return update(f.apply(1, body));
}

public static @NotNull Term unwrap(@NotNull Term term, @NotNull BooleanConsumer params) {
while (term instanceof LamTerm lambda) {
params.accept(lambda.explicit);
term = lambda.body;
}
return term;
}

public static @NotNull Term make(@NotNull SeqLike<Boolean> telescope, @NotNull Term body) {
return telescope.view().foldRight(body, LamTerm::new);
}
}

0 comments on commit 3895187

Please sign in to comment.