summaryrefslogtreecommitdiff
path: root/libraries/base/GHC/GHCi.hs
blob: 0370dfb19eb4029276cd6a6fcfbfa128255e41ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_HADDOCK not-home #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  GHC.GHCi
-- Copyright   :  (c) The University of Glasgow 2012
-- License     :  see libraries/base/LICENSE
--
-- Maintainer  :  cvs-ghc@haskell.org
-- Stability   :  internal
-- Portability :  non-portable (GHC Extensions)
--
-- The GHCi Monad lifting interface.
--
-- EXPERIMENTAL! DON'T USE.
--
-----------------------------------------------------------------------------

module GHC.GHCi {-# WARNING "This is an unstable interface." #-} (
        GHCiSandboxIO(..), NoIO()
    ) where

import GHC.Base (IO(), Monad, Functor(fmap), Applicative(..), (>>=), id, (.), ap)

-- | A monad that can execute GHCi statements by lifting them out of
-- m into the IO monad. (e.g state monads)
class (Monad m) => GHCiSandboxIO m where
    ghciStepIO :: m a -> IO a

-- | @since 4.4.0.0
instance GHCiSandboxIO IO where
    ghciStepIO = id

-- | A monad that doesn't allow any IO.
newtype NoIO a = NoIO { noio :: IO a }

-- | @since 4.8.0.0
instance Functor NoIO where
  fmap f (NoIO a) = NoIO (fmap f a)

-- | @since 4.8.0.0
instance Applicative NoIO where
  pure a = NoIO (pure a)
  (<*>) = ap

-- | @since 4.4.0.0
instance Monad NoIO where
    (>>=) k f = NoIO (noio k >>= noio . f)

-- | @since 4.4.0.0
instance GHCiSandboxIO NoIO where
    ghciStepIO = noio