Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. module Ex2 where
  2.  
  3. data Nat : Set where
  4. zero : Nat
  5. suc : Nat -> Nat
  6.  
  7. {-# BUILTIN NATURAL Nat #-}
  8.  
  9. data List (A : Set) : Set where
  10. [] : List A
  11. _::_ : A -> List A -> List A
  12.  
  13. infixr 40 _::_
  14.  
  15. _++_ : {A : Set} -> List A -> List A -> List A
  16. _++_ [] b = b
  17. _++_ (a :: as) b = a :: (as ++ b)
  18.  
  19. appx : ∀ {A} → Nat → List A → List A
  20. appx zero _ = []
  21. appx (suc x) a = a ++ (appx x a)
  22.  
  23. length : { A : Set } -> List A -> Nat
  24. length [] = zero
  25. length (_ :: as) = suc (length as)
  26.  
  27. firstX : ∀ {A} → Nat → List A → List A
  28. firstX x [] = []
  29. firstX zero l = []
  30. firstX (suc x) (v :: l) = v :: (firstX x l)
  31.  
  32.  
  33. data _==_ { A : Set} (x : A) : A -> Set where
  34. refl : x == x
  35.  
  36. --core module is locked, and must be referenced through functions
  37. module Core where
  38. private
  39. --Flag is significant to outer core and specifies some command.
  40. --since it's private, only functions within Core can create it
  41. data Flag : Set where
  42. flag : Flag
  43.  
  44.  
  45. call : (l : List Nat) -> length l == 10 -> Flag
  46. call x _ = flag
  47.  
  48. --attacker may make any changes here:
  49. module Scratch where
  50. l : List Nat
  51. l = appx 500 (1 :: 2 :: 3 :: [])
  52.  
  53. callInstance = Core.call l {! refl {x = (length!}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement