Commit 80608b85 authored by POTTIER Francois's avatar POTTIER Francois

Defined telescopes and implemented them in [map] and [endo].

parent 5b20b800
......@@ -36,6 +36,19 @@ let choose recursive env env' =
(* -------------------------------------------------------------------------- *)
(* A telescope is represented as a pair of a tele and a scope. A tele is a
list of bindings, where, in [(x, t) :: xts], the name [x] is considered
bound in [xts]. Furthermore, in a telescope [xts, u], all of the names
in the domain of [xts] are considered bound in [u]. *)
type ('bn, 't) tele =
('bn * 't) list
type ('bn, 't, 'u) telescope =
('bn, 't) tele * 'u
(* -------------------------------------------------------------------------- *)
(* The main effect of an abstraction is to cause the environment to be
enriched when the abstraction is traversed. The following classes define
where the environment is enriched. *)
......@@ -90,6 +103,29 @@ class virtual ['self] map = object (self : 'self)
let u2 = visit_u env' u1 in
recursive, x2, t2, u2
method visit_tele: 't1 't2 .
('env -> 't1 -> 't2) ->
'env -> ('bn1, 't1) tele -> ('bn2, 't2) tele * 'env
= fun visit_t env xts1 ->
match xts1 with
| [] ->
[], env
| (x1, t1) :: xts1 ->
let t2 = visit_t env t1 in
let x2, env = self#extend x1 env in
let xts2, env = self#visit_tele visit_t env xts1 in
(x2, t2) :: xts2, env
method visit_telescope: 't1 't2 'u1 'u2 .
_ ->
('env -> 't1 -> 't2) ->
('env -> 'u1 -> 'u2) ->
'env -> ('bn1, 't1, 'u1) telescope -> ('bn2, 't2, 'u2) telescope
= fun _ visit_t visit_u env (xts1, u1) ->
let xts2, env = self#visit_tele visit_t env xts1 in
let u2 = visit_u env u1 in
xts2, u2
end
(* -------------------------------------------------------------------------- *)
......@@ -129,6 +165,35 @@ class virtual ['self] endo = object (self : 'self)
else
recursive, x2, t2, u2
method visit_tele: 't .
('env -> 't -> 't) ->
'env -> ('bn, 't) tele -> ('bn, 't) tele * 'env
= fun visit_t env xts1 ->
match xts1 with
| [] ->
[], env
| ((x1, t1) :: xts1) as this ->
let t2 = visit_t env t1 in
let x2, env = self#extend x1 env in
let xts2, env = self#visit_tele visit_t env xts1 in
if x1 == x2 && t1 == t2 && xts1 == xts2 then
this, env
else
(x2, t2) :: xts2, env
method visit_telescope: 't 'u .
_ ->
('env -> 't -> 't) ->
('env -> 'u -> 'u) ->
'env -> ('bn, 't, 'u) telescope -> ('bn, 't, 'u) telescope
= fun _ visit_t visit_u env ((xts1, u1) as this) ->
let xts2, env = self#visit_tele visit_t env xts1 in
let u2 = visit_u env u1 in
if xts1 == xts2 && u1 == u2 then
this
else
xts2, u2
end
(* -------------------------------------------------------------------------- *)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment