@@ -86,6 +86,12 @@ instance MonadPlus Maybe where
86 mplus Nothing (Just y) = Just y
86 mplus Nothing (Just y) = Just y
87 mplus Nothing Nothing = Nothing
87 mplus Nothing Nothing = Nothing
89+instance Monad (Either e) where
92+ (Left n) >>= _ = Left n
93+ (Right r) >>= f = f r
89instance Monad List where
95instance Monad List where
90 return x = [x]
96 return x = [x]
91 m >>= f = concatMap f m
97 m >>= f = concatMap f m
@@ -100,6 +106,10 @@ instance Functor Maybe where
100 fmap f (Just x) = Just (f x)
106 fmap f (Just x) = Just (f x)
101 fmap f Nothing = Nothing
107 fmap f Nothing = Nothing
109+instance Functor (Either e) where
110+ fmap f (Left l) = Left l
111+ fmap f (Right r) = Right (f r)
103instance Functor List where
113instance Functor List where
104 fmap = map
114 fmap = map
@@ -111,6 +121,17 @@ instance Applicative Maybe where
111 (Just f) <$> (Just a) = Just (f a)
121 (Just f) <$> (Just a) = Just (f a)
112 _ <$> _ = Nothing
122 _ <$> _ = Nothing
124+instance Applicative (Either e) where
127+ (Left a) <$> _ = Left a
128+ (Right f) <$> (Right r) = Right (f r)
129+ (Right _) <$> (Left l) = Left l
131+instance Applicative List where
134+ fs <$> vs = concatMap (\f => map f vs) fs
115---- some mathematical operations
136---- some mathematical operations