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
SameColTypeis a reflexive relation. -
Show that
SameColTypeis a symmetric relation. -
Show that
SameColTypeis a transitive relation. -
Let
fbe a function of typeColType -> afor an arbitrary typea. Show that from a value of typeSameColType c1 c2follows thatf c1andf c2are equal.For
(=)the above properties are available from the Prelude as functionssym,trans, andcong. Reflexivity comes from the data constructorReflitself. -
Implement a function for verifying that two natural numbers are identical. Try using
congin your implementation. -
Use the function from exercise 5 for zipping two
Tables if they have the same number of rows.Hint: Use
Vect.zipWith. You will need to implement custom functionappRowsfor 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.