VecReverse.agda 1010 B

12345678910111213141516171819202122232425262728293031323334353637
  1. -- Andreas, 2020-12-16, also test #5103
  2. -- Allow compilation with unsolved metas
  3. {-# OPTIONS --allow-unsolved-metas #-}
  4. module _ where
  5. open import Common.Prelude
  6. open import Lib.Vec
  7. _∘_ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : ∀ x → B x → Set c}
  8. (f : ∀ {x} (y : B x) → C x y)
  9. (g : ∀ x → B x)
  10. → ∀ x → C x (g x)
  11. (f ∘ g) x = f (g x)
  12. sum : ∀ {n} → Vec Nat n → Nat
  13. sum (x ∷ xs) = x + sum xs
  14. sum [] = 0
  15. foldl : ∀ {A} (B : Nat → Set)
  16. → (∀ {n} → B n → A → B (suc n))
  17. → B 0
  18. → ∀ {n} → Vec A n → B n
  19. foldl B f z (x ∷ xs) = foldl (λ n → B (suc n)) f (f z x) xs
  20. foldl B f z [] = z
  21. reverse : ∀ {A n} → Vec A n → Vec A n
  22. reverse = foldl (Vec {!!}) (λ xs x → x ∷ xs) [] -- inessential unsolved meta here
  23. downFrom : ∀ n → Vec Nat n
  24. downFrom zero = []
  25. downFrom (suc n) = n ∷ downFrom n
  26. main : IO Unit
  27. main = printNat (sum (reverse (downFrom 600))) -- 10000 gives a stack overflow on JS