Exercises part 1
In these exercises, you'll have to implement several functions making use of auto implicits, to constrain the values accepted as function arguments. The results should be pure, that is, not wrapped in a failure type like Maybe
.
-
Implement
tail
for lists. -
Implement
concat1
andfoldMap1
for lists. These should work likeconcat
andfoldMap
, but taking only aSemigroup
constraint on the element type. -
Implement functions for returning the largest and smallest element in a list.
-
Define a predicate for strictly positive natural numbers and use it to implement a safe and provably total division function on natural numbers.
-
Define a predicate for a non-empty
Maybe
and use it to safely extract the value stored in aJust
. Show that this predicate is decidable by implementing a corresponding conversion function. -
Define and implement functions for safely extracting values from a
Left
and aRight
by using suitable predicates. Show again that these predicates are decidable.
The predicates you implemented in these exercises are already available in the base library: Data.List.NonEmpty
, Data.Maybe.IsJust
, Data.Either.IsLeft
, Data.Either.IsRight
, and Data.Nat.IsSucc
.