Debian Codegraph @

tests/inputs/Lookup.agda

raw
1 {-
2 https://raw.githubusercontent.com/agda/agda/master/examples/Lookup.agda
3 -}
4 module Lookup where
5
6 data Bool : Set where
7 false : Bool
8 true : Bool
9
10 data IsTrue : Bool -> Set where
11 isTrue : IsTrue true
12
13 data List (A : Set) : Set where
14 [] : List A
15 _::_ : A -> List A -> List A
16
17 data _×_ (A B : Set) : Set where
18 _,_ : A -> B -> A × B
19
20 module Map {- comment -}
21 (Key : Set)
22 (_==_ : Key -> Key -> Bool)
23 (Code : Set)
24 (Val : Code -> Set) where
25
26 infixr 40 _⟼_,_
27 infix 20 _∈_
28
29 data Map : List Code -> Set where
30 ε : Map []
31 _⟼_,_ : forall {c cs} ->
32 Key -> Val c -> Map cs -> Map (c :: cs)
33
34 _∈_ : forall {cs} -> Key -> Map cs -> Bool
35 k ∈ ε = false
36 k ∈ (k' ⟼ _ , m) with k == k'
37 ... | true = true
38 ... | false = k ∈ m
39
40 Lookup : forall {cs} -> (k : Key)(m : Map cs) -> IsTrue (k ∈ m) -> Set
41 Lookup k ε ()
42 Lookup k (_⟼_,_ {c} k' _ m) p with k == k'
43 ... | true = Val c
44 ... | false = Lookup k m p
45
46 lookup : {cs : List Code}(k : Key)(m : Map cs)(p : IsTrue (k ∈ m)) ->
47 Lookup k m p
48 lookup k ε ()
49 lookup k (k' ⟼ v , m) p with k == k'
50 ... | true = v
51 ... | false = lookup k m p