Exercises part 3
-
Show that there can be no non-empty vector of
Void
by writing a corresponding implementation of uninhabited -
Generalize exercise 1 for all uninhabited element types.
-
Show that if
a = b
cannot hold, thenb = a
cannot hold either. -
Show that if
a = b
holds, andb = c
cannot hold, thena = c
cannot hold either. -
Implement
Uninhabited
forCrud i a
. Try to be as general as possible.data Crud : (i : Type) -> (a : Type) -> Type where Create : (value : a) -> Crud i a Update : (id : i) -> (value : a) -> Crud i a Read : (id : i) -> Crud i a Delete : (id : i) -> Crud i a
-
Implement
DecEq
forColType
. -
Implementations such as the one from exercise 6 are cumbersome to write as they require a quadratic number of pattern matches with relation to the number of data constructors. Here is a trick how to make this more bearable.
-
Implement a function
ctNat
, which assigns every value of typeColType
a unique natural number. -
Proof that
ctNat
is injective. Hint: You will need to pattern match on theColType
values, but four matches should be enough to satisfy the coverage checker. -
In your implementation of
DecEq
forColType
, usedecEq
on the result of applying both column types toctNat
, thus reducing it to only two lines of code.
We will later talk about
with
rules: Special forms of dependent pattern matches, that allow us to learn something about the shape of function arguments by performing computations on them. These will allow us to use a similar technique as shown here to implementDecEq
requiring onlyn
pattern matches for arbitrary sum types withn
data constructors. -