Commit c6781a50 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺
Browse files

template-haskell: MRP-refactor Applicative/Monad instances

As `template-haskell` is compiled by stage1+ GHC only, we can
drop the explicit `return` definition rightaway.
parent 75c7cda2
......@@ -154,11 +154,10 @@ instance Functor PprM where
fmap = liftM
instance Applicative PprM where
pure = return
pure x = PprM $ \s -> (x, s)
(<*>) = ap
instance Monad PprM where
return x = PprM $ \s -> (x, s)
m >>= k = PprM $ \s -> let (x, s') = runPprM m s
in runPprM (k x) s'
......
......@@ -159,9 +159,8 @@ runQ :: Quasi m => Q a -> m a
runQ (Q m) = m
instance Monad Q where
return x = Q (return x)
Q m >>= k = Q (m >>= \x -> unQ (k x))
Q m >> Q n = Q (m >> n)
(>>) = (*>)
fail s = report True s >> Q (fail "Q monad failure")
instance Functor Q where
......@@ -170,6 +169,7 @@ instance Functor Q where
instance Applicative Q where
pure x = Q (pure x)
Q f <*> Q x = Q (f <*> x)
Q m *> Q n = Q (m *> n)
-----------------------------------------------------
--
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment