Skip to content

Commit

Permalink
Change the notation for first-class module projections to handle poly…
Browse files Browse the repository at this point in the history
…morphic fields
  • Loading branch information
clarus committed Jan 21, 2020
1 parent 9dabd80 commit 53a6b7b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion OCaml/Basics.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Local Open Scope Z_scope.
Import ListNotations.
Set Implicit Arguments.

Notation "record .[ field ]" := (field (projT2 record)) (at level 5).
Notation "(| record |)" := (projT2 record).

Module Primitive.
Set Primitive Projections.
Expand Down
10 changes: 8 additions & 2 deletions src/mixedPath.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ let of_path
let rec to_coq (path : t) : SmartPrint.t =
match path with
| Access (path, field_path_name, is_local) ->
to_coq path ^-^ !^ "." ^-^
(if is_local then parens else brakets) (PathName.to_coq field_path_name)
let path = to_coq path in
let path =
if is_local then
path
else
parens (!^ "|" ^-^ path ^-^ !^ "|") in
path ^-^ !^ "." ^-^
parens (PathName.to_coq field_path_name)
| PathName path_name -> PathName.to_coq path_name
24 changes: 13 additions & 11 deletions tests/first_class_modules.v
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,26 @@ Module UsingTriple.
End UsingTriple.

Definition set_update {a : Set} (v : a) (b : bool) (Box : set a) : set a :=
let elt_ty := Box.[Boxed_set.elt_ty] in
let OPS := Box.[Boxed_set.OPS] in
let elt_ty := (|Box|).(Boxed_set.elt_ty) in
let OPS := (|Box|).(Boxed_set.OPS) in
let boxed :=
if b then
Box.[Boxed_set.OPS].(S.SET.add) v Box.[Boxed_set.boxed]
(|Box|).(Boxed_set.OPS).(S.SET.add) v (|Box|).(Boxed_set.boxed)
else
Box.[Boxed_set.OPS].(S.SET.remove) v Box.[Boxed_set.boxed] in
(|Box|).(Boxed_set.OPS).(S.SET.remove) v (|Box|).(Boxed_set.boxed) in
let size :=
let mem := Box.[Boxed_set.OPS].(S.SET.mem) v Box.[Boxed_set.boxed] in
let mem := (|Box|).(Boxed_set.OPS).(S.SET.mem) v (|Box|).(Boxed_set.boxed)
in
if mem then
if b then
Box.[Boxed_set.size]
(|Box|).(Boxed_set.size)
else
Z.sub Box.[Boxed_set.size] 1
Z.sub (|Box|).(Boxed_set.size) 1
else
if b then
Z.add Box.[Boxed_set.size] 1
Z.add (|Box|).(Boxed_set.size) 1
else
Box.[Boxed_set.size] in
(|Box|).(Boxed_set.size) in
existT _ _
{|
Boxed_set.elt_ty := elt_ty;
Expand All @@ -165,10 +166,11 @@ Definition set_update {a : Set} (v : a) (b : bool) (Box : set a) : set a :=
|}.

Definition set_mem {elt : Set} (v : elt) (Box : set elt) : bool :=
Box.[Boxed_set.OPS].(S.SET.mem) v Box.[Boxed_set.boxed].
(|Box|).(Boxed_set.OPS).(S.SET.mem) v (|Box|).(Boxed_set.boxed).

Definition set_fold {acc elt : Set} (f : elt -> acc -> acc) (Box : set elt)
: acc -> acc := Box.[Boxed_set.OPS].(S.SET.fold) f Box.[Boxed_set.boxed].
: acc -> acc :=
(|Box|).(Boxed_set.OPS).(S.SET.fold) f (|Box|).(Boxed_set.boxed).

Module MAP.
Record signature {key : Set} {t : Set -> Set} := {
Expand Down
2 changes: 1 addition & 1 deletion tests/functor.v
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ End S.

Parameter Make :
forall (P : {t : _ & COMPARABLE.signature t}),
{_ : unit & S.signature P.[COMPARABLE.t]}.
{_ : unit & S.signature (|P|).(COMPARABLE.t)}.

Parameter Char : {_ : unit & S.signature ascii}.

Expand Down

0 comments on commit 53a6b7b

Please sign in to comment.