Skip to content

Commit 08b975a

Browse files
committed
Relax constraints for MaybeT Functor/Apply/Applicative instances
1 parent 1ac2e73 commit 08b975a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/Control/Monad/Maybe/Trans.purs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,20 @@ mapMaybeT f (MaybeT m) = MaybeT (f m)
4141

4242
derive instance newtypeMaybeT :: Newtype (MaybeT m a) _
4343

44-
instance functorMaybeT :: Monad m => Functor (MaybeT m) where
45-
map = liftA1
44+
instance functorMaybeT :: Functor m => Functor (MaybeT m) where
45+
map f (MaybeT ma) = MaybeT (map f <$> ma)
4646

47-
instance applyMaybeT :: Monad m => Apply (MaybeT m) where
48-
apply = ap
47+
instance applyMaybeT :: Apply m => Apply (MaybeT m) where
48+
apply (MaybeT f) (MaybeT x) = MaybeT (apply <$> f <*> x)
4949

50-
instance applicativeMaybeT :: Monad m => Applicative (MaybeT m) where
50+
instance applicativeMaybeT :: Applicative m => Applicative (MaybeT m) where
5151
pure = MaybeT <<< pure <<< Just
5252

5353
instance bindMaybeT :: Monad m => Bind (MaybeT m) where
5454
bind (MaybeT x) f = MaybeT do
55-
v <- x
56-
case v of
55+
x >>= case _ of
5756
Nothing -> pure Nothing
58-
Just y -> case f y of
59-
MaybeT m -> m
57+
Just y -> case f y of MaybeT m -> m
6058

6159
instance monadMaybeT :: Monad m => Monad (MaybeT m)
6260

0 commit comments

Comments
 (0)