Skip to content

Commit

Permalink
solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
nmheim committed May 8, 2024
1 parent e9b71c3 commit 01e057e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 0 additions & 2 deletions labs/lab10.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ of `xs` together with subsequences of `xs` extended by `x`. To produce the sorte
`merge` function.
:::

<!--
::: details Solution
```haskell
merge :: (a -> Int) -> [a] -> [a] -> [a]
Expand All @@ -318,4 +317,3 @@ subseqs [] = [[]]
subseqs (x:xs) = merge length (subseqs xs) [x:ys | ys <- subseqs xs]
```
:::
-->
9 changes: 8 additions & 1 deletion labs/lab11.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ Write a function `eval :: Expr Bool -> Bool` evaluating a given Boolean expressi
Logical operations negation, conjunction and disjunction can be respectively computed by `not, &&, ||`. The last two are infix operators.
:::

<!--
::: details Solution: `eval`
```haskell
eval :: Expr Bool -> Bool
Expand All @@ -234,6 +236,7 @@ getAtoms (And e1 e2) = getAtoms e1 ++ getAtoms e2
getAtoms (Or e1 e2) = getAtoms e1 ++ getAtoms e2
```
:::
-->

## Task 2
The type constructor `Expr` from the previous task can be made into an instance of `Functor` as follows:
Expand All @@ -252,12 +255,14 @@ subst :: Functor f => [String] -> f String -> f Bool
```
taking a list of strings (variables) and a data structure over strings returning the same data structure where the strings (variables) in the input list are replaced by `True` and the rest by `False`. Use the lifting by `fmap`.

<!--
::: details Solution: `subst`
```haskell
subst :: Functor f => [String] -> f String -> f Bool
subst xs = fmap (`elem` xs)
```
:::
-->

Next, apply the function `subseqs :: [a] -> [[a]]` from the previous lab returning a list of all sublists of a given list.
```haskell
Expand All @@ -277,6 +282,7 @@ such that the Boolean expression resulting from the replacing atoms by the respe
To check that there exists an evaluation satisfying a formula or if all evaluations satisfy the formula, use the functions `or`, `and` respectively. These functions are applicable to any list of Boolean values.
:::

<!--
::: details Solution: `isTaut, isSat`
```haskell
check :: ([Bool] -> Bool) -> Expr String -> Bool
Expand All @@ -287,4 +293,5 @@ isTaut, isSat :: Expr String -> Bool
isTaut = check and
isSat = check or
```
:::
:::
-->

0 comments on commit 01e057e

Please sign in to comment.