Skip to content

Commit fe39782

Browse files
committed
Add solutions to the composing types chapter
1 parent a0e1c77 commit fe39782

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module ComposingTypes.Twinplicative.Exercise where
2+
3+
import Control.Applicative (liftA2)
4+
5+
newtype Compose f g a = Compose { getCompose :: f (g a) }
6+
deriving (Eq, Show)
7+
8+
instance (Functor f, Functor g) => Functor (Compose f g) where
9+
fmap f (Compose fga) = Compose $ (fmap . fmap) f fga
10+
11+
instance (Applicative f, Applicative g) => Applicative (Compose f g) where
12+
pure = Compose . pure . pure
13+
Compose fgab <*> Compose fga = Compose $ liftA2 (<*>) fgab fga

0 commit comments

Comments
 (0)