{-# 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 :: IO a -> IO a
ghciStepIO = IO a -> IO a
forall a. a -> a
id

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

-- | @since 4.8.0.0
instance Functor NoIO where
  fmap :: (a -> b) -> NoIO a -> NoIO b
fmap f :: a -> b
f (NoIO a :: IO a
a) = IO b -> NoIO b
forall a. IO a -> NoIO a
NoIO ((a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f IO a
a)

-- | @since 4.8.0.0
instance Applicative NoIO where
  pure :: a -> NoIO a
pure a :: a
a = IO a -> NoIO a
forall a. IO a -> NoIO a
NoIO (a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a)
  <*> :: NoIO (a -> b) -> NoIO a -> NoIO b
(<*>) = NoIO (a -> b) -> NoIO a -> NoIO b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap

-- | @since 4.4.0.0
instance Monad NoIO where
    >>= :: NoIO a -> (a -> NoIO b) -> NoIO b
(>>=) k :: NoIO a
k f :: a -> NoIO b
f = IO b -> NoIO b
forall a. IO a -> NoIO a
NoIO (NoIO a -> IO a
forall a. NoIO a -> IO a
noio NoIO a
k IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= NoIO b -> IO b
forall a. NoIO a -> IO a
noio (NoIO b -> IO b) -> (a -> NoIO b) -> a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> NoIO b
f)

-- | @since 4.4.0.0
instance GHCiSandboxIO NoIO where
    ghciStepIO :: NoIO a -> IO a
ghciStepIO = NoIO a -> IO a
forall a. NoIO a -> IO a
noio