Issue3886.agda 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. -- Andreas, 2019-07-04, issue #3886
  2. -- Override forcing with explicit quantity attributes.
  3. open import Common.Prelude
  4. pattern [_] x = x ∷ []
  5. module _ {a} {A : Set a} where
  6. variable
  7. x y z : A
  8. @0 xs ys zs : List A
  9. data FSet : List A → Set a where
  10. ∅ : FSet []
  11. _∪_ : FSet xs → FSet ys → FSet (xs ++ ys)
  12. sg : (@ω x : A) → FSet [ x ]
  13. -- x is forced here, but this is not wanted.
  14. -- With an explicit quantity attribute we tell the forcing machinery not to erase x.
  15. -- Since xs is erased, we cannot get x from sg x : FSet xs (with xs = [ x ])
  16. -- unless x is retained in sg x.
  17. elements : {@0 xs : List A} → FSet xs → List A
  18. elements ∅ = []
  19. elements (s ∪ t) = elements s ++ elements t
  20. elements (sg x) = [ x ]
  21. -- ERROR WAS:
  22. -- Variable x is declared erased, so it cannot be used here
  23. -- when checking that the expression x has type A
  24. mySet = (sg 1 ∪ sg 2) ∪ (sg 3 ∪ sg 4)
  25. sum : List Nat → Nat
  26. sum [] = 0
  27. sum (n ∷ ns) = n + sum ns
  28. test = elements mySet
  29. main = printNat (sum (elements mySet))
  30. -- Should print 10.