What are sized types in Agda? I've tried to read the paper about MiniAgda, but failed to proceed due to the following points:
>
and #
patterns mean?sized data
, the compiler checks that the result is a type with the correct size, so that, for example, succ
in SNat
increases the size in 1. That way, for a sized type S
(i : Size) -> S i
is essentially an element of S
with size i
. What looks weird to me is why the definition of zero for SNat
is zero : (i : Size) -> SNat ($ i)
instead of something like zero : (i : Size) -> SNat ($ 0)
.As explained in section 2.3, #
is equivalent to T_∞, the type of elements of T with no known size bound; this is a top element for the T_i's in the subtyping preorder. The pattern (i > j) is used to bind a size j while keeping the information that j < i. The example in the paper for minus makes this clear:
fun minus : [i : Size] -> SNat i -> SNat # -> SNat i
{ minus i (zero (i > j)) y = zero j
; minus i x (zero .#) = x
; minus i (succ (i > j) x) (succ .# y) = minus j x y
}
First the signature means that substracting any number (SNat #
is a number with no size bound information) from a number of size at most i (that's what SNat i
means) returns a number of size at most i; and for the >
pattern, in the last line we use it to match a number of size at most j, and the recursive call type checks because of subtyping: SNat j ≤ SNat i
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With