Data.Char.digitToInt
[*](Prelude.^)
[*]Prelude.drop
[*]Prelude.take
Data.List.insert
[*]Differences from case distinction in mathematics:
|
instead of {
, and the equation sign is indented.Syntax:
|
guard expression =
expressionBool
.Semantics: Guard expressions are checked top-down, and the first satisfying condition is selected.
The two definitions are similar, but there are some minor differences.
Thus, the syntax is as follows.
Each of the cases is written in the following way:
|
guard (expression) =
expression
Guards are Boolean-type expressions.
Semantics: Guards are checked for satisfaction from the top to the bottom. The result will be the expression assigned to the first guard expression evaluating to true.
Note that otherwise
is not a keyword, but a constant defined in the Prelude
module.
Define the function upperLower
, which converts lowercase letters to uppercase ones and vice versa.
Hint: It requires the Data.Char
module to be imported.
Data.Char.digitToInt
[*]The following function assigns numeric values to characters:
(Prelude.^)
[*]Redefine the (^)
operator (quick exponentation).
Let toBin
be the function that returns a non-negative integer as series of binary numerals of the same value in reversed order.
Prelude.drop
[*]Definition of drop
:
Prelude.take
Redefine the take
function from the Prelude
module. Meaning of take n l
: take the first n
elements from the list l
.
Data.List.insert
[*]Redefine the insert
function from the Prelude
module (insertion of an element to a sorted list).
Define a sort merge.
Generate combinations of elements for a list without repetitions. (Let us consider the elements of the list distinct.)
Let n
a non-negative integer and xs
a list of non-negative integers.
Choose elements of xs
in all possible ways that the sum of the chosen integers must be n
.