Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions lib/kernel.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
open Std
open Common

module rec Memo : sig
val find : (ps * ty) -> Coh.t option
val add : (ps * ty) -> Coh.t -> Coh.t
end = struct
let tbl : (ps*ty, Coh.t) Hashtbl.t = Hashtbl.create 97

let find (ps,t) =
try Some (Hashtbl.find tbl (ps,t))
with Not_found -> None

let add (ps,t) coh =
Hashtbl.add tbl (ps,t) coh; coh
end

(** Operations on substitutions. *)
module rec Sub : sig
and Sub : sig
type t
val check_to_ps : Ctx.t -> sub_ps -> PS.t -> t
val forget : t -> sub
Expand Down Expand Up @@ -116,6 +130,7 @@ and PS : sig
val source : int -> t -> Var.t list
val target : int -> t -> Var.t list
val forget : t -> ps
val _to_string : t -> string
end
=
struct
Expand All @@ -131,6 +146,8 @@ struct

type t = {oldrep : oldrep; newrep : newt}

let _to_string t = Unchecked.ps_to_string t.newrep.tree

(** Create a context from a pasting scheme. *)
(* TODO:fix level of explicitness here *)
let old_rep_to_ctx ps =
Expand Down Expand Up @@ -308,6 +325,7 @@ and Ty : sig
val check : Ctx.t -> ty -> t
val apply : t -> Sub.t -> t
val expr : t -> expr
val _to_string : t -> string
end
=
struct
Expand Down Expand Up @@ -420,6 +438,7 @@ and Coh : sig
type t
val ps : t -> PS.t
val ty : t -> Ty.t
val algebraic : PS.t -> Ty.t -> (Var.t * int) list -> t
val check : ps -> ty -> (Var.t * int) list -> t
end
=
Expand Down Expand Up @@ -451,8 +470,12 @@ struct
(Printf.sprintf "checking coherence (%s,%s)"
(Unchecked.ps_to_string ps)
(Unchecked.ty_to_string t)));
let cps = Ctx.check (Unchecked.ps_to_ctx ps) in
let ps = PS.mk cps in
let t = Ty.check cps t in
algebraic ps t names
match Memo.find (ps,t) with
| Some coh -> coh
| None ->
let cps = Ctx.check (Unchecked.ps_to_ctx ps) in
let pps = PS.mk cps in
let tt = Ty.check cps t in
let coh = Coh.algebraic pps tt names in
Memo.add (ps,t) coh
end