(* Copyright 2018 IMDEA Software Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
(******************************************************************************)
(* This file contains an implementation of lift type adding an undef element  *)
(* a structure.                                                               *)
(* Lifting turns an unlifted structure into a PCM and preserves equality.     *)
(******************************************************************************)
Module Unlifted.
Record mixin_of (T : Type) := Mixin {
ounit_op : T;
ojoin_op : T -> T -> option T;
ojoinC_op : forall x y, ojoin_op x y = ojoin_op y x;
ojoinA_op : forall x y z,
obind (ojoin_op x) (ojoin_op y z) = obind (ojoin_op^~ z) (ojoin_op x y);
ounitL_op : forall x, ojoin_op ounit_op x = Some x}.
Section ClassDef.
Notation class_of := mixin_of (only parsing).
Structure type : Type := Pack {sort : Type; _ : class_of sort}.
Local Coercion sort : type >-> Sortclass.
Variables (T : Type) (cT : type).
Definition class := let: Pack _ c as cT' := cT return class_of cT' in c.
Definition pack c := @Pack T c.
Definition clone := fun c & cT -> T & phant_id (pack c) cT => pack c.
Definition ounit := ounit_op class.
Definition ojoin := ojoin_op class.
End ClassDef.
Module Exports.
Coercion sort : type >-> Sortclass.
Notation unlifted := type.
Notation UnliftedMixin := Mixin.
Notation Unlifted T m := (@pack T m).
Notation "[ 'unliftedMixin' 'of' T ]" := (class _ : mixin_of T)
(at level 0, format "[ 'unliftedMixin'  'of'  T ]") : form_scope.
Notation "[ 'unlifted' 'of' T 'for' C ]" := (@clone T C _ idfun id)
(at level 0, format "[ 'unlifted'  'of'  T  'for'  C ]") : form_scope.
Notation "[ 'unlifted' 'of' T ]" := (@clone T _ _ id id)
(at level 0, format "[ 'unlifted'  'of'  T ]") : form_scope.
Notation ounit := ounit.
Notation ojoin := ojoin.
Arguments ounit [cT].

Lemma ojoinC (U : unlifted) (x y : U) : ojoin x y = ojoin y x.