module Functions.Cases where open import Sets.Enumerated using (Bool; true; false)
Representation of negation as a function from Bool to Bool:
not : Bool → Bool not true = false not false = true
We pattern match on the elements that appear in set Bool namely true and false to define how the function works.
We have elements of Bool like
not true : Boolnot (not (not false)) : Bool
but these are not new elements: their normal form is either true or false.
In the interactive environment we can compute the normal form by C-c C-n.
Functions have computational content.
For example, not defines not just a relation between Bool and Bool, but also an algorithm how to compute the negated value.
Logical AND could be defined with four alternatives but here is a shorter definition with two alternatives with variables:
_∧_ : Bool → Bool → Bool true ∧ x = x false ∧ _ = false infixr 6 _∧_
_∧_ denote the space for the operands.infixr gives the fixity_∨_infixr 5 _∨_ _∨_ : Bool → Bool → Bool
not and _∧_!Define a set named Answer with three elements, yes, no and maybe.
Define logical operations on Answer!
Define a set named Quarter with four elements, east, west, north and south.
Define a function turnLeft : Quarter → Quarter.
Define the functions turnBack and turnRight with the help of turnLeft! (By either pattern matching or defining a specific function composition function.)