annotate Paper/src/AgdaSingleLinkedStack.agda.replaced @ 5:339fb67b4375

INIT rbt.agda
author soto <soto@cr.ie.u-ryukyu.ac.jp>
date Sun, 07 Nov 2021 00:51:16 +0900
parents c59202657321
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
339fb67b4375 INIT rbt.agda
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1 singleLinkedStackSpec : {n m : Level } {t : Set m } {a : Set n} !$\rightarrow$! StackMethods {n} {m} a {t} (SingleLinkedStack a)
0
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 singleLinkedStackSpec = record {
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 push = pushSingleLinkedStack
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 ; pop = popSingleLinkedStack
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 ; pop2 = pop2SingleLinkedStack
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 ; get = getSingleLinkedStack
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 ; get2 = get2SingleLinkedStack
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 ; clear = clearSingleLinkedStack
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 }
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
5
339fb67b4375 INIT rbt.agda
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
11 createSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} !$\rightarrow$! Stack {n} {m} a {t} (SingleLinkedStack a)
0
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 createSingleLinkedStack = record {
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 stack = emptySingleLinkedStack ;
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 stackMethods = singleLinkedStackSpec
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 }
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 -- Implementation
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
5
339fb67b4375 INIT rbt.agda
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
19 pushSingleLinkedStack : {n m : Level } {t : Set m } {Data : Set n} !$\rightarrow$! SingleLinkedStack Data !$\rightarrow$! Data !$\rightarrow$! (Code : SingleLinkedStack Data !$\rightarrow$! t) !$\rightarrow$! t
0
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 pushSingleLinkedStack stack datum next = next stack1
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 where
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 element = cons datum (top stack)
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 stack1 = record {top = Just element}
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
5
339fb67b4375 INIT rbt.agda
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
26 popSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} !$\rightarrow$! SingleLinkedStack a !$\rightarrow$! (Code : SingleLinkedStack a !$\rightarrow$! (Maybe a) !$\rightarrow$! t) !$\rightarrow$! t
0
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 popSingleLinkedStack stack cs with (top stack)
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 ... | Nothing = cs stack Nothing
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 ... | Just d = cs stack1 (Just data1)
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 where
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 data1 = datum d
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 stack1 = record { top = (next d) }
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
5
339fb67b4375 INIT rbt.agda
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
34 pop2SingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} !$\rightarrow$! SingleLinkedStack a !$\rightarrow$! (Code : SingleLinkedStack a !$\rightarrow$! (Maybe a) !$\rightarrow$! (Maybe a) !$\rightarrow$! t) !$\rightarrow$! t
0
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 pop2SingleLinkedStack {n} {m} {t} {a} stack cs with (top stack)
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 ... | Nothing = cs stack Nothing Nothing
5
339fb67b4375 INIT rbt.agda
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
37 ... | Just d = pop2SingleLinkedStack!$\prime$! {n} {m} stack cs
0
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 where
5
339fb67b4375 INIT rbt.agda
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
39 pop2SingleLinkedStack!$\prime$! : {n m : Level } {t : Set m } !$\rightarrow$! SingleLinkedStack a !$\rightarrow$! (Code : SingleLinkedStack a !$\rightarrow$! (Maybe a) !$\rightarrow$! (Maybe a) !$\rightarrow$! t) !$\rightarrow$! t
339fb67b4375 INIT rbt.agda
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
40 pop2SingleLinkedStack!$\prime$! stack cs with (next d)
0
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 ... | Nothing = cs stack Nothing Nothing
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 ... | Just d1 = cs (record {top = (next d1)}) (Just (datum d)) (Just (datum d1))
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
5
339fb67b4375 INIT rbt.agda
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
45 getSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} !$\rightarrow$! SingleLinkedStack a !$\rightarrow$! (Code : SingleLinkedStack a !$\rightarrow$! (Maybe a) !$\rightarrow$! t) !$\rightarrow$! t
0
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 getSingleLinkedStack stack cs with (top stack)
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 ... | Nothing = cs stack Nothing
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 ... | Just d = cs stack (Just data1)
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 where
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 data1 = datum d
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
5
339fb67b4375 INIT rbt.agda
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
52 get2SingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} !$\rightarrow$! SingleLinkedStack a !$\rightarrow$! (Code : SingleLinkedStack a !$\rightarrow$! (Maybe a) !$\rightarrow$! (Maybe a) !$\rightarrow$! t) !$\rightarrow$! t
0
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 get2SingleLinkedStack {n} {m} {t} {a} stack cs with (top stack)
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 ... | Nothing = cs stack Nothing Nothing
5
339fb67b4375 INIT rbt.agda
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
55 ... | Just d = get2SingleLinkedStack!$\prime$! {n} {m} stack cs
0
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 where
5
339fb67b4375 INIT rbt.agda
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
57 get2SingleLinkedStack!$\prime$! : {n m : Level} {t : Set m } !$\rightarrow$! SingleLinkedStack a !$\rightarrow$! (Code : SingleLinkedStack a !$\rightarrow$! (Maybe a) !$\rightarrow$! (Maybe a) !$\rightarrow$! t) !$\rightarrow$! t
339fb67b4375 INIT rbt.agda
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
58 get2SingleLinkedStack!$\prime$! stack cs with (next d)
0
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 ... | Nothing = cs stack Nothing Nothing
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 ... | Just d1 = cs stack (Just (datum d)) (Just (datum d1))
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
5
339fb67b4375 INIT rbt.agda
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
62 clearSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} !$\rightarrow$! SingleLinkedStack a !$\rightarrow$! (SingleLinkedStack a !$\rightarrow$! t) !$\rightarrow$! t
0
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 clearSingleLinkedStack stack next = next (record {top = Nothing})