Issue4168-4185.agda 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. -- Andreas, 2019-11-12, issue #4168b
  2. --
  3. -- Meta variable solver should not use uncurrying
  4. -- if the record type contains erased fields.
  5. open import Agda.Builtin.Equality
  6. open import Agda.Builtin.Sigma
  7. open import Common.IO
  8. P : (A B : Set) → (A → B) → Set
  9. P A B f = (y : B) → Σ A (λ x → f x ≡ y)
  10. record R (A B : Set) : Set where
  11. field
  12. to : A → B
  13. from : B → A
  14. from-to : (x : A) → from (to x) ≡ x
  15. p : (A B : Set) (r : R A B) → P A B (R.to r)
  16. p _ _ r y = R.from r y , to-from y
  17. where
  18. postulate
  19. to-from : ∀ x → R.to r (R.from r x) ≡ x
  20. record Box (A : Set) : Set where
  21. constructor box
  22. field
  23. @0 unbox : A
  24. test : (A : Set) → P (Box A) (Box (Box A)) (λ x → box {A = Box A} x)
  25. test A = p _ _ (record
  26. { to = λ x → box {A = _} x
  27. ; from = λ { (box (box x)) → box {A = A} x }
  28. -- at first, a postponed type checking problem ?from
  29. ; from-to = λ x → refl {A = Box A} {x = x}
  30. })
  31. -- from-to creates constraint
  32. --
  33. -- x : Box A |- ?from (box x) = x : Box A
  34. --
  35. -- This was changed to
  36. --
  37. -- y : Box (Box A) |- ?from y = unbox y : Box A
  38. --
  39. -- which is an invalid transformation since x is not
  40. -- guaranteed to be in erased context.
  41. -- As a consequence, compilation (GHC backend) failed.
  42. -- A variant with a non-erased field.
  43. record ⊤ : Set where
  44. record Box' (A : Set) : Set where
  45. constructor box'
  46. field
  47. unit : ⊤
  48. @0 unbox' : A
  49. test' : (A : Set) → P (Box' A) (Box' (Box' A)) (λ x → box' {A = Box' A} _ x)
  50. test' A = p _ _ (record
  51. { to = λ x → box' {A = _} _ x
  52. ; from = λ { (box' _ (box' _ x)) → box' {A = A} _ x }
  53. ; from-to = λ x → refl {A = Box' A} {x = x}
  54. })
  55. -- UPDATE (2019-11-17):
  56. -- We may, however, uncurry if the record argument is erased.
  57. mutual
  58. X : {@0 A : Set} (@0 b : Box A) → Box (Box A)
  59. X = _
  60. spec : ∀{@0 A : Set} {@0 x : A}
  61. → X (box x) ≡ box (box x)
  62. spec = refl
  63. -- This can be solved by:
  64. -- X := λ {@0 A} (@0 b) → box (box (Box.unbox b))
  65. main : IO ⊤
  66. main = return _