(* Copyright 2012 Google Inc. * * 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. * * Authors: Russell O'Connor *)
Require Vector.
Set Asymmetric Patterns.
Set Implicit Arguments.
Unset Strict Implicit.
Record KleeneStore i j a := kleeneStore
{ dim : nat
; peek : Vector.t j dim -> a
; pos : Vector.t i dim
}.
Definition extract i a (s : KleeneStore i i a) : a :=
peek (pos s).
Definition KSmap i j a b (f : a -> b) (s : KleeneStore i j a) : KleeneStore i j b :=
kleeneStore (fun v => f (peek v)) (pos s).
Definition duplicate i j k a (s : KleeneStore i k a) :
KleeneStore i j (KleeneStore j k a) :=
kleeneStore (fun v => kleeneStore (peek (k:=s)) v) (pos s).
Record KleeneCoalg (i o : Type -> Type) := kleeneCoalg
{ coalg :> forall a b, (o a) -> KleeneStore (i a) (i b) (o b)
; coalg_extract : forall a (x:o a), extract (coalg _ x) = x
; coalg_duplicate : forall a b c (x:o a),
duplicate (i b) (coalg c x) = KSmap (coalg c) (coalg b x)
}.

Lemma free_b_dim i o (k : KleeneCoalg i o) a b b' (x : o a) : dim (coalg k b x) = dim (coalg k b' x).