Exercises part 3
-
Show that there can be no non-empty vector of
Voidby writing a corresponding implementation of uninhabited -
Generalize exercise 1 for all uninhabited element types.
-
Show that if
a = bcannot hold, thenb = acannot hold either. -
Show that if
a = bholds, andb = ccannot hold, thena = ccannot hold either. -
Implement
UninhabitedforCrud 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
DecEqforColType. -
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 typeColTypea unique natural number. -
Proof that
ctNatis injective. Hint: You will need to pattern match on theColTypevalues, but four matches should be enough to satisfy the coverage checker. -
In your implementation of
DecEqforColType, usedecEqon the result of applying both column types toctNat, thus reducing it to only two lines of code.
We will later talk about
withrules: 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 implementDecEqrequiring onlynpattern matches for arbitrary sum types withndata constructors. -