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
tailfor lists. -
Implement
concat1andfoldMap1for lists. These should work likeconcatandfoldMap, but taking only aSemigroupconstraint 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
Maybeand 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
Leftand aRightby 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.