Interestingly enough, your first version is actually correct. I mentioned that Agda enables few extra rules considering Size
, one of them being ↑ ∞ ≡ ∞
. By the way, you can confirm it via:
↑inf : ↑ ∞ ≡ ∞
↑inf = refl
Well, this led me to investigate what the other rules are. I found the rest of them inside Andreas Abel's slides on sized types (can be found here):
↑ ∞ ≡ ∞
i ≤ ↑ i ≤ ∞
T {i} <: T {↑ i} <: T {∞}
The <:
relation is the subtyping relation, which you might know from object oriented languages. There's also a rule associated with this relation, the subsumption rule:
Γ ⊢ x : A Γ ⊢ A <: B
────────────────────── (sub)
Γ ⊢ x : B
So, if you have a value x
of type A
and you know that A
is a subtype of B
, you can treat x
as being of type B
as well. This seemed strange, because following the subtyping rule for sized types, you should be able to treat a value of type SortedList l u {ι}
as SortedList l u
.
So I did bit of a digging and found this bug report. And indeed, the problem is just that Agda doesn't correctly recognize the size and the rule doesn't fire. All I needed to do was to rewrite the definition of SortedList
to:
data SortedList (l u : A) : {ι : Size} → Set (𝒂 ⊔ ℓ) where
-- ...
And that's it!
As an addendum, here's the code I used for testing:
data ℕ : {ι : _} → Set where -- does not work
-- data ℕ : {ι : Size} → Set where -- works
zero : ∀ {ι} → ℕ {↑ ι}
suc : ∀ {ι} → ℕ {ι} → ℕ {↑ ι}
test : ∀ {ι} → ℕ {ι} → ℕ
test n = n