fixed error
This commit is contained in:
parent
4e500b2c05
commit
352b1be3f2
@ -57,7 +57,7 @@ mystery3 f a l = post a l'
|
|||||||
where
|
where
|
||||||
l' = map f l
|
l' = map f l
|
||||||
post a (x:xs)
|
post a (x:xs)
|
||||||
| a == x = x ++ post a xs
|
| a == x = x : post a xs
|
||||||
| otherwise = post a xs
|
| otherwise = post a xs
|
||||||
post _ [] = []
|
post _ [] = []
|
||||||
|
|
||||||
|
@ -6,10 +6,8 @@ Throat-Clearing
|
|||||||
|
|
||||||
a.k.a. Imports, damit der Code funktioniert.
|
a.k.a. Imports, damit der Code funktioniert.
|
||||||
|
|
||||||
``` {.haskell}
|
> import Data.Functor
|
||||||
import Data.Functor
|
> import Data.Monoid
|
||||||
import Data.Monoid
|
|
||||||
```
|
|
||||||
|
|
||||||
Functor
|
Functor
|
||||||
-------
|
-------
|
||||||
@ -23,20 +21,18 @@ Erinnerung:
|
|||||||
Nehmen sie an, sie hätten folgende Datentypen gegeben, für die alle eine
|
Nehmen sie an, sie hätten folgende Datentypen gegeben, für die alle eine
|
||||||
`Functor`-Instanz existiert und eindeutig ist:
|
`Functor`-Instanz existiert und eindeutig ist:
|
||||||
|
|
||||||
``` {.haskell}
|
> data Identity a = Identity { unIdentity :: a }
|
||||||
data Identity a = Identity { unIdentity :: a }
|
>
|
||||||
|
> data Vielleicht a = Etwas a
|
||||||
data Vielleicht a = Etwas a
|
> | Nichts
|
||||||
| Nichts
|
>
|
||||||
|
> data EntwederOder b a = Entweder a
|
||||||
data EntwederOder b a = Entweder a
|
> | Oder b
|
||||||
| Oder b
|
>
|
||||||
|
> data GameVector b a = V3 a a a
|
||||||
data GameVector b a = V3 a a a
|
> | VStrange [a]
|
||||||
| VStrange [a]
|
> | Neighbours [GameVector b a]
|
||||||
| Neighbours [GameVector b a]
|
> | EntwederOder b (GameVector b a)
|
||||||
| EntwederOder b (GameVector b a)
|
|
||||||
```
|
|
||||||
|
|
||||||
Schreiben sie hierzu die jeweiligen `Functor`-Instanzen.
|
Schreiben sie hierzu die jeweiligen `Functor`-Instanzen.
|
||||||
|
|
||||||
@ -52,35 +48,33 @@ Kann die Funktion nachher mehr als vorher?
|
|||||||
|
|
||||||
*Bonus*: Hat sich an der Laufzeit etwas verändert?
|
*Bonus*: Hat sich an der Laufzeit etwas verändert?
|
||||||
|
|
||||||
``` {.haskell}
|
> mystery1 :: [[a]] -> [[a]]
|
||||||
mystery1 :: [[a]] -> [[a]]
|
> mystery1 = map (++[])
|
||||||
mystery1 = map (++[])
|
>
|
||||||
|
> mystery2 :: (Eq a) => a -> a -> a -> Bool
|
||||||
mystery2 :: (Eq a) => a -> a -> a -> Bool
|
> mystery2 x y z
|
||||||
mystery2 x y z
|
> | x == y || y == z = True
|
||||||
| x == y || y == z = True
|
> | x == y && y == z = True
|
||||||
| x == y && y == z = True
|
> | x /= z = False
|
||||||
| x /= z = False
|
> | y /= z = False
|
||||||
| y /= z = False
|
> | x == y || y /= z = True
|
||||||
| x == y || y /= z = True
|
> | otherwise = False
|
||||||
| otherwise = False
|
>
|
||||||
|
> mystery3 :: Eq a => (a -> a) -> a -> [a] -> [a]
|
||||||
mystery3 :: Eq a => (a -> a) -> a -> [a] -> [a]
|
> mystery3 f a l = post a l'
|
||||||
mystery3 f a l = post a l'
|
> where
|
||||||
where
|
> l' = map f l
|
||||||
l' = map f l
|
> post a (x:xs)
|
||||||
post a (x:xs)
|
> | a == x = x : post a xs
|
||||||
| a == x = x ++ post a xs
|
> | otherwise = post a xs
|
||||||
| otherwise = post a xs
|
> post _ [] = []
|
||||||
post _ [] = []
|
>
|
||||||
|
> mystery4 :: (Int -> Bool)
|
||||||
mystery4 :: (Int -> Bool)
|
> -> Vielleicht (EntwederOder String Int)
|
||||||
-> Vielleicht (EntwederOder String Int)
|
> -> Vielleicht (EntwederOder String Bool)
|
||||||
-> Vielleicht (EntwederOder String Bool)
|
> mystery4 f (Etwas (Entweder a)) = Etwas . Entweder . f $ a
|
||||||
mystery4 f (Etwas (Entweder a)) = Etwas . Entweder . f $ a
|
> mystery4 _ (Etwas (Oder b)) = Etwas (Oder b)
|
||||||
mystery4 _ (Etwas (Oder b)) = Etwas (Oder b)
|
> mystery4 _ Nichts = Nichts
|
||||||
mystery4 _ Nichts = Nichts
|
|
||||||
```
|
|
||||||
|
|
||||||
Bonus
|
Bonus
|
||||||
-----
|
-----
|
||||||
|
@ -62,7 +62,7 @@ mystery3 f a l = post a l'
|
|||||||
where
|
where
|
||||||
l' = map f l
|
l' = map f l
|
||||||
post a (x:xs)
|
post a (x:xs)
|
||||||
| a == x = x ++ post a xs
|
| a == x = x : post a xs
|
||||||
| otherwise = post a xs
|
| otherwise = post a xs
|
||||||
post _ [] = []
|
post _ [] = []
|
||||||
|
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user