Mercurial > hg > Gears > GearsAgda
view src/parallel_execution/stack.agda @ 156:0aa2265660a0
Add stack lemma
author | atton |
---|---|
date | Tue, 15 Nov 2016 20:17:31 +0900 |
parents | 19cc626943e4 |
children | 3fdb3334c7a9 |
line wrap: on
line source
module stack where record Stack {a : Set} (stackImpl : Set a) where stack : stackImpl push : stackImpl -> a -> (stackImpl -> T) -> T pop : stackImpl -> (stackImpl -> maybe a -> T) -> T createSingleLinkedStack : Stack (SingleLinkedStack {a}) createSingleLinkedStack = record { stack = record { top = nothing;} push = pushSingleLinkedStack; pop = popSingleLinkedStack; } record Element {a : Set} : Set where data : a next : Maybe (Element a) record SingleLinkedStack {a : Set} : Set where top : Maybe (Element a) pushSingleLinkedStack : Stack -> Data -> (Code : Stack -> T) -> T pushSingleLinkedStack stack data next = next stack1 where element = record {next = top stack; data = data} stack1 = record {top = just element} popSingleLinkedStack : {a : Set} -> Maybe a -> (Code : Stack -> (Maybe a) -> T) -> T popSingleLinkedStack stack data next with (top stack) = ... | nothing = next stack nothing ... | just a = next stack1 data1 where data1 = data a stack1 = record { top = (next a)} test01 : Stack -> Maybe a -> T test01 stack nothing = false test01 stack (just _) = true test02 : Stack -> T test02 stack = (pop stack) test01 test03 : T test03 = push createSingleLinkedStack true test02 lemma : test01 == false lemma = refl