annotate paper/src/stackImpl.agda @ 2:c7acb9211784

add code, figure. and paper fix content
author ryokka
date Mon, 27 Jan 2020 20:41:36 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
1 record Element {l : Level} (a : Set l) : Set l where
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
2 inductive
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
3 constructor cons
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
4 field
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
5 datum : a -- `data` is reserved by Agda.
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
6 next : Maybe (Element a)
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
7 open Element
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
8
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
9 record SingleLinkedStack {n : Level } (a : Set n) : Set n where
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
10 field
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
11 top : Maybe (Element a)
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
12 open SingleLinkedStack
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
13
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
14 pushSingleLinkedStack : {n m : Level } {t : Set m } {Data : Set n} -> SingleLinkedStack Data -> Data -> (Code : SingleLinkedStack Data -> t) -> t
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
15 pushSingleLinkedStack stack datum next = next stack1
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
16 where
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
17 element = cons datum (top stack)
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
18 stack1 = record {top = Just element}
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
19
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
20 -- push 以下は省略
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
21
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
22 -- Basic stack implementations are specifications of a Stack
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
23
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
24 singleLinkedStackSpec : {n m : Level } {t : Set m } {a : Set n} -> StackMethods {n} {m} a {t} (SingleLinkedStack a)
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
25 singleLinkedStackSpec = record {
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
26 push = pushSingleLinkedStack
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
27 ; pop = popSingleLinkedStack
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
28 ; pop2 = pop2SingleLinkedStack
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
29 ; get = getSingleLinkedStack
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
30 ; get2 = get2SingleLinkedStack
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
31 ; clear = clearSingleLinkedStack
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
32 }
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
33
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
34 createSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} -> Stack {n} {m} a {t} (SingleLinkedStack a)
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
35 createSingleLinkedStack = record {
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
36 stack = emptySingleLinkedStack ;
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
37 stackMethods = singleLinkedStackSpec
c7acb9211784 add code, figure. and paper fix content
ryokka
parents:
diff changeset
38 }