Haskell/Solutions/Understanding arrows
(>>>)
| Exercises |
|---|
| What is the type of the combined arrow? |
The combined arrow has type a b d.
first
| Exercises |
|---|
What is the type of the first robot? |
first :: a b c -> a (b,d) (c,d)
second
| Exercises |
|---|
|
swap :: (a,b) -> (b,a) swap (a,b) = (b,a) second :: (Arrow a) => a b c -> a (d,b) (d,c) second a = arr swap >>> first a >>> arr swap
(***)
| Exercises |
|---|
|
(***) :: a b d -> a c e -> a (b,c) (d,e) f *** g = first f >>> second g
(&&&)
| Exercises |
|---|
addA f g = f &&& g >>> arr (\ (y, z) -> y + z) |
clone a = (a,a) f &&& g = arr clone >>> f *** g addA f g = arr clone >>> f *** g >>> arr (\(y,z) -> y + z) -- OR addA f g = arr clone >>> f *** g >>> arr (uncurry (+))
Arrow combinators (robots)
| Exercises |
|---|
|
FIXME: No solutions.