Exercises part 1
In the following exercises, you are going to implement some very basic properties of equality proofs. You'll have to come up with the types of the functions yourself, as the implementations will be incredibly simple.
Note: If you can't remember what the terms "reflexive", "symmetric", and "transitive" mean, quickly read about equivalence relations.
-
Show that
SameColType
is a reflexive relation. -
Show that
SameColType
is a symmetric relation. -
Show that
SameColType
is a transitive relation. -
Let
f
be a function of typeColType -> a
for an arbitrary typea
. Show that from a value of typeSameColType c1 c2
follows thatf c1
andf c2
are equal.For
(=)
the above properties are available from the Prelude as functionssym
,trans
, andcong
. Reflexivity comes from the data constructorRefl
itself. -
Implement a function for verifying that two natural numbers are identical. Try using
cong
in your implementation. -
Use the function from exercise 5 for zipping two
Table
s if they have the same number of rows.Hint: Use
Vect.zipWith
. You will need to implement custom functionappRows
for this, since Idris will not automatically figure out that the types unify when usingHList.(++)
:appRows : {ts1 : _} -> Row ts1 -> Row ts2 -> Row (ts1 ++ ts2)
We will later learn how to use rewrite rules to circumvent the need of writing custom functions like appRows
and use (++)
in zipWith
directly.