Make Applicative a superclass of Monad
[ghc.git] / libraries / base / GHC / GHCi.hs
1 {-# LANGUAGE NoImplicitPrelude #-}
2 {-# OPTIONS_HADDOCK hide #-}
3
4 -----------------------------------------------------------------------------
5 -- |
6 -- Module : GHC.GHCi
7 -- Copyright : (c) The University of Glasgow 2012
8 -- License : see libraries/base/LICENSE
9 --
10 -- Maintainer : cvs-ghc@haskell.org
11 -- Stability : internal
12 -- Portability : non-portable (GHC Extensions)
13 --
14 -- The GHCi Monad lifting interface.
15 --
16 -- EXPERIMENTAL! DON'T USE.
17 --
18 -----------------------------------------------------------------------------
19
20 module GHC.GHCi {-# WARNING "This is an unstable interface." #-} (
21 GHCiSandboxIO(..), NoIO()
22 ) where
23
24 import GHC.Base (IO(), Monad, Functor(fmap), Applicative(..), (>>=), return, id, (.), ap)
25
26 -- | A monad that can execute GHCi statements by lifting them out of
27 -- m into the IO monad. (e.g state monads)
28 class (Monad m) => GHCiSandboxIO m where
29 ghciStepIO :: m a -> IO a
30
31 instance GHCiSandboxIO IO where
32 ghciStepIO = id
33
34 -- | A monad that doesn't allow any IO.
35 newtype NoIO a = NoIO { noio :: IO a }
36
37 instance Functor NoIO where
38 fmap f (NoIO a) = NoIO (fmap f a)
39
40 instance Applicative NoIO where
41 pure = return
42 (<*>) = ap
43
44 instance Monad NoIO where
45 return a = NoIO (return a)
46 (>>=) k f = NoIO (noio k >>= noio . f)
47
48 instance GHCiSandboxIO NoIO where
49 ghciStepIO = noio
50