Dear Gitlab users, as announced previously (and here), we will be downgrading this Gitlab instance delayed to the Community edition on Thursday, 25.08.22, at 5 pm. You may ignore the (upcoming) banner below displayed by Gitlab.
use list comprehensions for creating the following sets in haskell
- $A = \{ x \,:\, x \in \mathbb{N},\, x \text{ odd}\}$ (only showing the first 5 elements)
- $B = \{ -x \,:\, x \in \mathbb{N},\, 3|x ,\, x < 10\}$ ($3|x$ : 3 is a divisor of x)
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 4
Create the set of all odd numbers smaller than 500, which are dividable through 5 and 7.
$S=\{x : x \neq 0 \land 5|x \land 7|x\}$
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
# problem 5
Let $A=\{1,2,3\}$, $B=\{3,4,5\}$. Calculate the intersection and the union of $A$ and $B$.
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 6
Let `less` and `greater` be functions which have a value `v` and a list of values `l` of the same type as `v`. Return a list of all values which are less or greater as `v`.
$\text{less}(v,l) = \{x : x \in l, x < v\}$
Implement the functions using list comprehensions.
Test: `5 [1..10]`
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 7
the list generated with `[0.1,0.3..0.9]` has problems with precision (has roundingerror). Do it better via using list comprehensions. (Tip: ranges of integral types do not have rounding errors).
and change the type to `Int -> Int`. Which consequences does this have, and how can you show it?
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 3
- Write a function taking two numbers as arguments, the edge lengths of a rectangle, and returns the area.
- the function should be able to work with arbitrary type of numbers (besides complex)
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 4
Write a function accepting three strings and returning the lexicographically largest one.
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 5
Write a function accepting a list of arbitrary numbers and returning the mean value.
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 6
Write a function that accepts a number and a tuple (e.g. `("left", "right")`) and returns the first element of the tuple if the digit `0` is in the number, and the second element otherwise.
For tuples with 2 elements, `fst` and `snd` extract the first and second component, respectively. Write functions `fst3`, `snd3` and `thr3` that work on tuples with 3 elements.
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 4
Write a function `reverseMe :: String -> String` that reverses its argument. Proceed as follows:
- empty strings are left unchanged
- non-empty strings are split into first letter and rest
- `reverseMe` is then recursively applied to the rest, and the first letter is appended (note the type of `(++)`)
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 5
- Write a function `initial` that returns the first letter of a string.
- Use Hoogle or Hayoo to find a function that splits a string into words (*Hint*: What should be the type of that function? Type signatures can be directly used for searching.)
- Write a function `initials` that accepts a name in the form "Firstname Middlename Lastname" and returns the initials in the form "F. M. L."
Write a function which checks if a given number is inside an also given range. If the number is in range, return its string representation, and if not, return `"out of bounds"`.
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
problem 4
---------
Write a function which takes a list and checks if its empty, has one or more than one element. It returns the following strings depending on the length of the list
$0$: "The list is empty"
$1$: "The list has one element"
$>1$: "The list has more than one element"
do not use `length` but pattern matching and/or `case`
- write a function `applyThrice` analogous to `applyTwice` from the lecture.
- write a function `applyThrice'` without using an argument, thus
```haskell
applyThrice'f=...
```
%% Cell type:code id: tags:
``` haskell
```
%%Celltype:markdownid:tags:
##problem2
writeinpointfree-style:
-`fx=(+)5$(/)8x`
-`gx=mod4$div16$2*$x+2`
%%Celltype:codeid:tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 3
write the following functions as lambda functions
- $h(x) = x^2 + x \% 5$.
- the `hasVowal` function.
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 4
Write a function `gt100`, which checks if a parameter is greater than 100
- normal
- pointfree
- as anonymous
- as pointfree anonymous function
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 5
Let
```haskell
multThree :: (Num a) => a -> a -> a -> a
multThree x y z = x * y * z
```
be a function for multiplying three numbers with each other. Use partial function evaluation to get a function which has one parameter and multiplies with 49.
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 6
- write a function `flipFunct`, which gets a function of two arguments and returns a function which has the arguments flipped.
- check the function with the `-`
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 7
rewrite the following function such that it only contains function composition and application operators. Avoid as usual brackets.
Write a function `firstIndexWhere` that accepts a predicate `a -> Bool` and a list `[a]` and returns the index of the first element at which the predicate returns `True`.