IdentitySmashing.agda 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. -- {-# OPTIONS -v treeless.opt:20 #-}
  2. -- Andreas, 2019-05-07, #3732: cannot have treeless printout in golden value
  3. -- because it is different for the MAlonzo and JS versions now.
  4. open import Agda.Builtin.Nat
  5. open import Common.IO using (return)
  6. open import Agda.Builtin.Unit
  7. data List {a} (A : Set a) : Set a where
  8. [] : List A
  9. _∷_ : A → List A → List A
  10. data Vec {a} (A : Set a) : ..(_ : Nat) → Set a where
  11. [] : Vec A 0
  12. _∷_ : ∀ ..{n} → A → Vec A n → Vec A (suc n)
  13. -- We can't handle smashing this yet. Different backends might compile
  14. -- datatypes differently so we can't guarantee representational
  15. -- compatibility. Possible solution: handle datatype compilation in
  16. -- treeless as well and be explicit about which datatypes compile to the
  17. -- same representation.
  18. vecToList : ∀ {a} {A : Set a} ..{n} → Vec A n → List A
  19. vecToList [] = []
  20. vecToList (x ∷ xs) = x ∷ vecToList xs
  21. data Fin : ..(_ : Nat) → Set where
  22. zero : ∀ ..{n} → Fin (suc n)
  23. suc : ∀ ..{n} → Fin n → Fin (suc n)
  24. -- These should all compile to identity functions:
  25. wk : ∀ ..{n} → Fin n → Fin (suc n)
  26. wk zero = zero
  27. wk (suc i) = suc (wk i)
  28. wkN : ∀ ..{n m} → Fin n → Fin (n + m)
  29. wkN zero = zero
  30. wkN (suc i) = suc (wkN i)
  31. wkN′ : ∀ m ..{n} → Fin n → Fin (m + n)
  32. wkN′ zero i = i
  33. wkN′ (suc m) i = wk (wkN′ m i)
  34. vecPlusZero : ∀ {a} {A : Set a} ..{n} → Vec A n → Vec A (n + 0)
  35. vecPlusZero [] = []
  36. vecPlusZero (x ∷ xs) = x ∷ vecPlusZero xs
  37. main = return tt