Lookup.agda 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. module Lookup where
  2. data Bool : Set where
  3. false : Bool
  4. true : Bool
  5. data IsTrue : Bool -> Set where
  6. isTrue : IsTrue true
  7. data List (A : Set) : Set where
  8. [] : List A
  9. _::_ : A -> List A -> List A
  10. data _×_ (A B : Set) : Set where
  11. _,_ : A -> B -> A × B
  12. module Map
  13. (Key : Set)
  14. (_==_ : Key -> Key -> Bool)
  15. (Code : Set)
  16. (Val : Code -> Set) where
  17. infixr 40 _⟼_,_
  18. infix 20 _∈_
  19. data Map : List Code -> Set where
  20. ε : Map []
  21. _⟼_,_ : forall {c cs} ->
  22. Key -> Val c -> Map cs -> Map (c :: cs)
  23. _∈_ : forall {cs} -> Key -> Map cs -> Bool
  24. k ∈ ε = false
  25. k ∈ (k' ⟼ _ , m) with k == k'
  26. ... | true = true
  27. ... | false = k ∈ m
  28. Lookup : forall {cs} -> (k : Key)(m : Map cs) -> IsTrue (k ∈ m) -> Set
  29. Lookup k ε ()
  30. Lookup k (_⟼_,_ {c} k' _ m) p with k == k'
  31. ... | true = Val c
  32. ... | false = Lookup k m p
  33. lookup : {cs : List Code}(k : Key)(m : Map cs)(p : IsTrue (k ∈ m)) ->
  34. Lookup k m p
  35. lookup k ε ()
  36. lookup k (k' ⟼ v , m) p with k == k'
  37. ... | true = v
  38. ... | false = lookup k m p