Skip to content

Commit

Permalink
Change from Fin to typing predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
Edwin Brady committed Jul 7, 2011
1 parent 4006f11 commit 9cd6510
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions imp.idr
@@ -1,34 +1,36 @@

update : (i:Fin n) -> a -> Vect a n -> Vect a n;
update fO y (x :: xs) = y :: xs;
update (fS k) y (x :: xs) = x :: update k y xs;

using (gam : Vect Set n, gam' : Vect Set n, gam'' : Vect Set n) { using (gam : Vect Set n, gam' : Vect Set n, gam'' : Vect Set n) {


infixl 5 := ; infixl 5 := ;


data HasType : Vect Set n -> Fin n -> Set -> Set where
stop : HasType (a :: gam) fO a
| pop : HasType gam i b -> HasType (a :: gam) (fS i) b;

update : (gam : Vect Set n) -> HasType gam i b -> Set -> Vect Set n;
update (x :: xs) stop y = y :: xs;
update (x :: xs) (pop k) y = x :: update xs k y;

data [noElim] Imp : Vect Set n -> Vect Set n' -> Set -> Set where data [noElim] Imp : Vect Set n -> Vect Set n' -> Set -> Set where
Let : A -> Imp (A :: gam) (B :: gam') T -> Imp gam gam' T Let : A -> Imp (A :: gam) (B :: gam') T -> Imp gam gam' T
| (:=) : (i:Fin n) -> B -> Imp gam (update i B gam) () | (:=) : (p:HasType gam i A) -> B -> Imp gam (update gam p B) ()
| Read : (i:Fin n) -> Imp gam gam (vlookup i gam) | Read : HasType gam i A -> Imp gam gam A
| While : Imp gam gam Bool -> Imp gam gam () -> Imp gam gam () | While : Imp gam gam Bool -> Imp gam gam () -> Imp gam gam ()
| Return : A -> Imp gam gam A | Return : A -> Imp gam gam A
| Bind : Imp gam gam' A -> (A -> Imp gam' gam'' T) -> | Bind : Imp gam gam' A -> (A -> Imp gam' gam'' T) ->
Imp gam gam'' T; Imp gam gam'' T;



data Env : Vect Set n -> Set where data Env : Vect Set n -> Set where
Empty : Env VNil Empty : Env VNil
| Extend : a -> Env gam -> Env (a :: gam); | Extend : a -> Env gam -> Env (a :: gam);


envLookup : (i:Fin n) -> Env gam -> vlookup i gam; envLookup : HasType gam i A -> Env gam -> A;
envLookup fO (Extend x xs) = x; envLookup stop (Extend x xs) = x;
envLookup (fS k) (Extend x xs) = envLookup k xs; envLookup (pop k) (Extend x xs) = envLookup k xs;


envUpdate : (i:Fin n) -> (val:a) -> envUpdate : (p:HasType gam i A) -> (val:B) ->
Env gam -> Env (update i a gam); Env gam -> Env (update gam p B);
envUpdate fO val (Extend x xs) = Extend val xs; envUpdate stop val (Extend x xs) = Extend val xs;
envUpdate (fS k) val (Extend x xs) = Extend x (envUpdate k val xs); envUpdate (pop k) val (Extend x xs) = Extend x (envUpdate k val xs);


envTail : Env (a :: gam) -> Env gam; envTail : Env (a :: gam) -> Env gam;
envTail (Extend x xs) = xs; envTail (Extend x xs) = xs;
Expand All @@ -49,7 +51,6 @@ using (gam : Vect Set n, gam' : Vect Set n, gam'' : Vect Set n) {
interp env (Bind v k) = let venv = interp env v in interp env (Bind v k) = let venv = interp env v in
interp (snd venv) (k (fst venv)); interp (snd venv) (k (fst venv));



run : Imp VNil VNil t -> t; run : Imp VNil VNil t -> t;
run prog = fst (interp Empty prog); run prog = fst (interp Empty prog);


Expand All @@ -60,6 +61,8 @@ dsl imp {
return = Return return = Return
variable = id variable = id
let = Let let = Let
index_first = stop
index_next = pop
} }


syntax IMP x = #( {gam:Vect Set n} -> Imp gam gam x ); syntax IMP x = #( {gam:Vect Set n} -> Imp gam gam x );
Expand Down

0 comments on commit 9cd6510

Please sign in to comment.