5using namespace std::string_literals;
15 auto ret =
dom(num_doms() - 1);
41 if (
auto app =
body()->isa<App>())
42 if (
app->arg() ==
var && !
app->callee()->free_vars().contains(
var))
return app->callee();
49 auto eta = w.mut_lam(f->type()->as<
Pi>());
50 eta->debug_suffix(
"eta_"s + f->sym().str());
51 return eta->app(
filter, f, eta->var());
59 auto& world = f->world();
60 world.DLOG(
"compose f (B->C): {} : {}", f, f->type());
61 world.DLOG(
"compose g (A->B): {} : {}", g, g->type());
63 auto F = f->type()->as<
Pi>();
64 auto G = g->type()->as<
Pi>();
69 auto A = G->
dom(2, 0);
71 auto C = F->ret_dom();
74 world.DLOG(
"compose f (B->C): {} : {}", f, F);
75 world.DLOG(
"compose g (A->B): {} : {}", g, G);
76 world.DLOG(
" A: {}", A);
77 world.DLOG(
" B: {}", B);
78 world.DLOG(
" C: {}", C);
80 auto h = world.mut_fun(A, C)->set(
"comp_"s + f->sym().str() +
"_"s + g->sym().str());
81 auto hcont = world.mut_con(B)->set(
"comp_"s + f->sym().str() +
"_"s + g->sym().str() +
"_cont"s);
83 h->app(
true, g, {h->var((
nat_t)0), hcont});
85 auto hcont_var = hcont->var();
86 hcont->app(
true, f, {hcont_var, h->var(1) });
Def * set(size_t i, const Def *)
Successively set from left to right.
World & world() const noexcept
const Def * var(nat_t a, nat_t i) noexcept
const Var * has_var()
Only returns not nullptr, if Var of this mutable has ever been created.
std::variant< bool, const Def * > Filter
const Def * filter() const
Lam * branch(Filter filter, const Def *cond, const Def *t, const Def *f, const Def *mem=nullptr)
Set body to an App of (f, t)#cond mem or (f, t)#cond () if mem is nullptr.
Lam * set(Filter filter, const Def *body)
Lam * set_filter(Filter)
Set filter first.
const Def * eta_reduce() const
Yields body(), if eta-convertible and nullptr otherwise.
Lam * app(Filter filter, const Def *callee, const Def *arg)
Set body to an App of callee and arg.
Lam * set_body(const Def *body)
Set body second.
static const Def * eta_expand(Filter, const Def *f)
A dependent function type.
const Def * ret_dom() const
Pi::domain of Pi::ret_pi.
Pi(const Def *type, const Def *dom, const Def *codom, bool implicit)
Constructor for an immutable Pi.
static const Pi * isa_basicblock(const Def *d)
Is this a continuation (Pi::isa_cn) that is not Pi::isa_returning?
const Pi * ret_pi() const
Yields the last Pi::dom, if Pi::isa_basicblock.
Pi * set_dom(const Def *dom)
static const Pi * isa_returning(const Def *d)
Is this a continuation (Pi::isa_cn) which has a Pi::ret_pi?
const Def * filter(Lam::Filter filter)
const Def * compose_cn(const Def *f, const Def *g)
The high level view is: