aboutsummaryrefslogtreecommitdiff
path: root/src/elaborator
diff options
context:
space:
mode:
authorMalte Voos <git@mal.tc>2024-06-30 15:07:02 +0200
committerMalte Voos <git@mal.tc>2024-06-30 15:07:02 +0200
commitfab70aaf2947ff1369757355fbf11437c6db35ff (patch)
treedb4a00cb43cb4c3833091d5a7cd0423a99fb7f82 /src/elaborator
parentb34ebf3fe3ecaf292be873d231dd54c80f16ad07 (diff)
downloadtoytt-fab70aaf2947ff1369757355fbf11437c6db35ff.tar.gz
toytt-fab70aaf2947ff1369757355fbf11437c6db35ff.zip
implement syntax for non-dependent function and pair types
Diffstat (limited to 'src/elaborator')
-rw-r--r--src/elaborator/Elaborator.ml31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/elaborator/Elaborator.ml b/src/elaborator/Elaborator.ml
index df2a358..ba1da02 100644
--- a/src/elaborator/Elaborator.ml
+++ b/src/elaborator/Elaborator.ml
@@ -53,19 +53,17 @@ let quote v = NbE.quote ~size:(Eff.read()).size v
(** Pretty-printing helpers *)
let pp () = let names = (Eff.read()).names in fun fmt tm ->
- Pretty.pp ~names fmt tm
+ Pretty.pp ~names fmt tm
(** Main algorithm *)
+type connective = [ `Pi | `Sigma ]
+
let rec check ~(tm : A.expr) ~(tp : D.t) : S.t =
Error.tracef ?loc:tm.loc "when checking against the type @[%a@]" (pp()) (quote tp) @@ fun () ->
match tm.value with
- | A.Pi ((name, base), fam) -> begin match tp with
- | D.Type ->
- let base = check ~tm:base ~tp in
- let fam = bind ~name:name.value ~tp:(eval base) @@ fun _ -> check ~tm:fam ~tp in
- S.Pi (name.value, base, fam)
- | _ -> Error.fatalf Error.Message.IllTyped "expected an element of type @[%a@], but found an element of a universe" (pp()) (quote tp) end
+ | A.Pi ((name, base), fam) -> check_connective `Pi ~name:name.value ~base ~fam ~tp
+ | A.Fun (base, fam) -> check_connective `Pi ~name:None ~base ~fam ~tp
| A.Lam (name, body) -> begin match tp with
| D.Pi (_, base, fam) ->
let body = bind ~name:name.value ~tp:base @@ fun arg ->
@@ -74,12 +72,8 @@ let rec check ~(tm : A.expr) ~(tp : D.t) : S.t =
S.Lam (name.value, body)
| _ -> Error.fatalf Error.Message.IllTyped "expected an element of type @[%a@], but found an element of a Pi type" (pp()) (quote tp)
end
- | A.Sg ((name, base), fam) -> begin match tp with
- | D.Type ->
- let base = check ~tm:base ~tp in
- let fam = bind ~name:name.value ~tp:(eval base) @@ fun _ -> check ~tm:fam ~tp in
- S.Sg (name.value, base, fam)
- | _ -> Error.fatalf Error.Message.IllTyped "expected an element of type @[%a@], but found an element of a universe" (pp()) (quote tp) end
+ | A.Sg ((name, base), fam) -> check_connective `Sigma ~name:name.value ~base ~fam ~tp
+ | A.Prod (base, fam) -> check_connective `Sigma ~name:None ~base ~fam ~tp
| A.Pair (fst, snd) -> begin match tp with
| D.Sg (_, base, fam) ->
let fst = check ~tm:fst ~tp:base in
@@ -111,6 +105,17 @@ let rec check ~(tm : A.expr) ~(tp : D.t) : S.t =
end;
tm
+and check_connective connective ~(name : Ident.local) ~(base : A.expr) ~(fam : A.expr) ~(tp : D.t) =
+ match tp with
+ | D.Type ->
+ let base = check ~tm:base ~tp in
+ let fam = bind ~name:name ~tp:(eval base) @@ fun _ -> check ~tm:fam ~tp in
+ begin match connective with
+ | `Pi -> S.Pi (name, base, fam)
+ | `Sigma -> S.Sg (name, base, fam)
+ end
+ | _ -> Error.fatalf Error.Message.IllTyped "expected an element of type @[%a@], but found an element of a universe" (pp()) (quote tp)
+
and infer (tm : A.expr) : D.t * S.t =
Error.tracef ?loc:tm.loc "when inferring the type" @@ fun () ->
match tm.value with