{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE NoPolyKinds #-}
module GHC.Tc.Zonk.Env
(
ZonkEnv(..), getZonkEnv
, ZonkFlexi(..)
, initZonkEnv
, ZonkT(ZonkT,runZonkT), ZonkBndrT(..)
, runZonkBndrT
, noBinders, don'tBind
, setZonkType
, extendZonkEnv
, extendIdZonkEnv, extendIdZonkEnvRec
, extendTyZonkEnv
)
where
import GHC.Prelude
import GHC.Core.TyCo.Rep ( Type )
import GHC.Types.Var ( TyCoVar, Var, TyVar )
import GHC.Types.Var ( Id, isTyCoVar )
import GHC.Types.Var.Env
import GHC.Utils.Monad.Codensity
import GHC.Utils.Outputable
import Control.Monad.Fix ( MonadFix(..) )
import Control.Monad.IO.Class ( MonadIO(..) )
import Control.Monad.Trans.Class ( MonadTrans(..) )
import Data.Coerce ( coerce )
import Data.IORef ( IORef, newIORef )
import Data.List ( partition )
import GHC.Exts ( oneShot )
data ZonkEnv
= ZonkEnv { ZonkEnv -> ZonkFlexi
ze_flexi :: !ZonkFlexi
, ZonkEnv -> TyCoVarEnv TyCoVar
ze_tv_env :: TyCoVarEnv TyCoVar
, ZonkEnv -> TyCoVarEnv TyCoVar
ze_id_env :: IdEnv Id
, ZonkEnv -> IORef (TyVarEnv Type)
ze_meta_tv_env :: IORef (TyVarEnv Type) }
data ZonkFlexi
= DefaultFlexi
| SkolemiseFlexi
| RuntimeUnkFlexi
| NoFlexi
instance Outputable ZonkEnv where
ppr :: ZonkEnv -> SDoc
ppr (ZonkEnv { ze_tv_env :: ZonkEnv -> TyCoVarEnv TyCoVar
ze_tv_env = TyCoVarEnv TyCoVar
tv_env
, ze_id_env :: ZonkEnv -> TyCoVarEnv TyCoVar
ze_id_env = TyCoVarEnv TyCoVar
id_env })
= String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ZE" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
braces ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
[ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ze_tv_env =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TyCoVarEnv TyCoVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCoVarEnv TyCoVar
tv_env
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ze_id_env =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TyCoVarEnv TyCoVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCoVarEnv TyCoVar
id_env ])
newtype ZonkT m a = ZonkT' { forall (m :: * -> *) a. ZonkT m a -> ZonkEnv -> m a
runZonkT :: ZonkEnv -> m a }
{-# COMPLETE ZonkT #-}
pattern ZonkT :: forall m a. (ZonkEnv -> m a) -> ZonkT m a
pattern $mZonkT :: forall {r} {m :: * -> *} {a}.
ZonkT m a -> ((ZonkEnv -> m a) -> r) -> ((# #) -> r) -> r
$bZonkT :: forall (m :: * -> *) a. (ZonkEnv -> m a) -> ZonkT m a
ZonkT m <- ZonkT' m
where
ZonkT ZonkEnv -> m a
m = (ZonkEnv -> m a) -> ZonkT m a
forall (m :: * -> *) a. (ZonkEnv -> m a) -> ZonkT m a
ZonkT' ((ZonkEnv -> m a) -> ZonkEnv -> m a
forall a b. (a -> b) -> a -> b
oneShot ZonkEnv -> m a
m)
instance Functor m => Functor (ZonkT m) where
fmap :: forall a b. (a -> b) -> ZonkT m a -> ZonkT m b
fmap a -> b
f (ZonkT ZonkEnv -> m a
g) = (ZonkEnv -> m b) -> ZonkT m b
forall (m :: * -> *) a. (ZonkEnv -> m a) -> ZonkT m a
ZonkT ((ZonkEnv -> m b) -> ZonkT m b) -> (ZonkEnv -> m b) -> ZonkT m b
forall a b. (a -> b) -> a -> b
$ \ !ZonkEnv
env -> (a -> b) -> m a -> m b
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (ZonkEnv -> m a
g ZonkEnv
env)
a
a <$ :: forall a b. a -> ZonkT m b -> ZonkT m a
<$ ZonkT ZonkEnv -> m b
g = (ZonkEnv -> m a) -> ZonkT m a
forall (m :: * -> *) a. (ZonkEnv -> m a) -> ZonkT m a
ZonkT ((ZonkEnv -> m a) -> ZonkT m a) -> (ZonkEnv -> m a) -> ZonkT m a
forall a b. (a -> b) -> a -> b
$ \ !ZonkEnv
env -> a
a a -> m b -> m a
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ZonkEnv -> m b
g ZonkEnv
env
{-# INLINE fmap #-}
{-# INLINE (<$) #-}
instance Applicative m => Applicative (ZonkT m) where
pure :: forall a. a -> ZonkT m a
pure a
a = (ZonkEnv -> m a) -> ZonkT m a
forall (m :: * -> *) a. (ZonkEnv -> m a) -> ZonkT m a
ZonkT (\ !ZonkEnv
_ -> a -> m a
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a)
ZonkT ZonkEnv -> m (a -> b)
f <*> :: forall a b. ZonkT m (a -> b) -> ZonkT m a -> ZonkT m b
<*> ZonkT ZonkEnv -> m a
x = (ZonkEnv -> m b) -> ZonkT m b
forall (m :: * -> *) a. (ZonkEnv -> m a) -> ZonkT m a
ZonkT (\ !ZonkEnv
env -> ZonkEnv -> m (a -> b)
f ZonkEnv
env m (a -> b) -> m a -> m b
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ZonkEnv -> m a
x ZonkEnv
env )
ZonkT ZonkEnv -> m a
m *> :: forall a b. ZonkT m a -> ZonkT m b -> ZonkT m b
*> ZonkT m b
f = (ZonkEnv -> m b) -> ZonkT m b
forall (m :: * -> *) a. (ZonkEnv -> m a) -> ZonkT m a
ZonkT (\ !ZonkEnv
env -> ZonkEnv -> m a
m ZonkEnv
env m a -> m b -> m b
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ZonkT m b -> ZonkEnv -> m b
forall (m :: * -> *) a. ZonkT m a -> ZonkEnv -> m a
runZonkT ZonkT m b
f ZonkEnv
env)
{-# INLINE pure #-}
{-# INLINE (<*>) #-}
{-# INLINE (*>) #-}
instance Monad m => Monad (ZonkT m) where
ZonkT ZonkEnv -> m a
m >>= :: forall a b. ZonkT m a -> (a -> ZonkT m b) -> ZonkT m b
>>= a -> ZonkT m b
f =
(ZonkEnv -> m b) -> ZonkT m b
forall (m :: * -> *) a. (ZonkEnv -> m a) -> ZonkT m a
ZonkT (\ !ZonkEnv
env -> do { r <- ZonkEnv -> m a
m ZonkEnv
env
; runZonkT (f r) env })
>> :: forall a b. ZonkT m a -> ZonkT m b -> ZonkT m b
(>>) = ZonkT m a -> ZonkT m b -> ZonkT m b
forall a b. ZonkT m a -> ZonkT m b -> ZonkT m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)
{-# INLINE (>>=) #-}
{-# INLINE (>>) #-}
instance MonadIO m => MonadIO (ZonkT m) where
liftIO :: forall a. IO a -> ZonkT m a
liftIO IO a
f = (ZonkEnv -> m a) -> ZonkT m a
forall (m :: * -> *) a. (ZonkEnv -> m a) -> ZonkT m a
ZonkT (\ !ZonkEnv
_ -> IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO a
f)
{-# INLINE liftIO #-}
instance MonadTrans ZonkT where
lift :: forall (m :: * -> *) a. Monad m => m a -> ZonkT m a
lift m a
ma = (ZonkEnv -> m a) -> ZonkT m a
forall (m :: * -> *) a. (ZonkEnv -> m a) -> ZonkT m a
ZonkT ((ZonkEnv -> m a) -> ZonkT m a) -> (ZonkEnv -> m a) -> ZonkT m a
forall a b. (a -> b) -> a -> b
$ \ !ZonkEnv
_ -> m a
ma
{-# INLINE lift #-}
instance MonadFix m => MonadFix (ZonkT m) where
mfix :: forall a. (a -> ZonkT m a) -> ZonkT m a
mfix a -> ZonkT m a
f = (ZonkEnv -> m a) -> ZonkT m a
forall (m :: * -> *) a. (ZonkEnv -> m a) -> ZonkT m a
ZonkT ((ZonkEnv -> m a) -> ZonkT m a) -> (ZonkEnv -> m a) -> ZonkT m a
forall a b. (a -> b) -> a -> b
$ \ !ZonkEnv
r -> (a -> m a) -> m a
forall a. (a -> m a) -> m a
forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
mfix ((a -> m a) -> m a) -> (a -> m a) -> m a
forall a b. (a -> b) -> a -> b
$ (a -> m a) -> a -> m a
forall a b. (a -> b) -> a -> b
oneShot ((a -> m a) -> a -> m a) -> (a -> m a) -> a -> m a
forall a b. (a -> b) -> a -> b
$ \ a
a -> ZonkT m a -> ZonkEnv -> m a
forall (m :: * -> *) a. ZonkT m a -> ZonkEnv -> m a
runZonkT (a -> ZonkT m a
f a
a) ZonkEnv
r
{-# INLINE mfix #-}
newtype ZonkBndrT m a = ZonkBndrT { forall (m :: * -> *) a.
ZonkBndrT m a -> forall r. (a -> ZonkT m r) -> ZonkT m r
runZonkBndrT' :: forall r. (a -> ZonkT m r) -> ZonkT m r }
deriving ((forall a b. (a -> b) -> ZonkBndrT m a -> ZonkBndrT m b)
-> (forall a b. a -> ZonkBndrT m b -> ZonkBndrT m a)
-> Functor (ZonkBndrT m)
forall a b. a -> ZonkBndrT m b -> ZonkBndrT m a
forall a b. (a -> b) -> ZonkBndrT m a -> ZonkBndrT m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (m :: * -> *) a b. a -> ZonkBndrT m b -> ZonkBndrT m a
forall (m :: * -> *) a b.
(a -> b) -> ZonkBndrT m a -> ZonkBndrT m b
$cfmap :: forall (m :: * -> *) a b.
(a -> b) -> ZonkBndrT m a -> ZonkBndrT m b
fmap :: forall a b. (a -> b) -> ZonkBndrT m a -> ZonkBndrT m b
$c<$ :: forall (m :: * -> *) a b. a -> ZonkBndrT m b -> ZonkBndrT m a
<$ :: forall a b. a -> ZonkBndrT m b -> ZonkBndrT m a
Functor, Functor (ZonkBndrT m)
Functor (ZonkBndrT m) =>
(forall a. a -> ZonkBndrT m a)
-> (forall a b.
ZonkBndrT m (a -> b) -> ZonkBndrT m a -> ZonkBndrT m b)
-> (forall a b c.
(a -> b -> c) -> ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m c)
-> (forall a b. ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m b)
-> (forall a b. ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m a)
-> Applicative (ZonkBndrT m)
forall a. a -> ZonkBndrT m a
forall a b. ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m a
forall a b. ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m b
forall a b. ZonkBndrT m (a -> b) -> ZonkBndrT m a -> ZonkBndrT m b
forall a b c.
(a -> b -> c) -> ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m c
forall (m :: * -> *). Functor (ZonkBndrT m)
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (m :: * -> *) a. a -> ZonkBndrT m a
forall (m :: * -> *) a b.
ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m a
forall (m :: * -> *) a b.
ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m b
forall (m :: * -> *) a b.
ZonkBndrT m (a -> b) -> ZonkBndrT m a -> ZonkBndrT m b
forall (m :: * -> *) a b c.
(a -> b -> c) -> ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m c
$cpure :: forall (m :: * -> *) a. a -> ZonkBndrT m a
pure :: forall a. a -> ZonkBndrT m a
$c<*> :: forall (m :: * -> *) a b.
ZonkBndrT m (a -> b) -> ZonkBndrT m a -> ZonkBndrT m b
<*> :: forall a b. ZonkBndrT m (a -> b) -> ZonkBndrT m a -> ZonkBndrT m b
$cliftA2 :: forall (m :: * -> *) a b c.
(a -> b -> c) -> ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m c
liftA2 :: forall a b c.
(a -> b -> c) -> ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m c
$c*> :: forall (m :: * -> *) a b.
ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m b
*> :: forall a b. ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m b
$c<* :: forall (m :: * -> *) a b.
ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m a
<* :: forall a b. ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m a
Applicative, Applicative (ZonkBndrT m)
Applicative (ZonkBndrT m) =>
(forall a b.
ZonkBndrT m a -> (a -> ZonkBndrT m b) -> ZonkBndrT m b)
-> (forall a b. ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m b)
-> (forall a. a -> ZonkBndrT m a)
-> Monad (ZonkBndrT m)
forall a. a -> ZonkBndrT m a
forall a b. ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m b
forall a b. ZonkBndrT m a -> (a -> ZonkBndrT m b) -> ZonkBndrT m b
forall (m :: * -> *). Applicative (ZonkBndrT m)
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
forall (m :: * -> *) a. a -> ZonkBndrT m a
forall (m :: * -> *) a b.
ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m b
forall (m :: * -> *) a b.
ZonkBndrT m a -> (a -> ZonkBndrT m b) -> ZonkBndrT m b
$c>>= :: forall (m :: * -> *) a b.
ZonkBndrT m a -> (a -> ZonkBndrT m b) -> ZonkBndrT m b
>>= :: forall a b. ZonkBndrT m a -> (a -> ZonkBndrT m b) -> ZonkBndrT m b
$c>> :: forall (m :: * -> *) a b.
ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m b
>> :: forall a b. ZonkBndrT m a -> ZonkBndrT m b -> ZonkBndrT m b
$creturn :: forall (m :: * -> *) a. a -> ZonkBndrT m a
return :: forall a. a -> ZonkBndrT m a
Monad, Monad (ZonkBndrT m)
Monad (ZonkBndrT m) =>
(forall a. IO a -> ZonkBndrT m a) -> MonadIO (ZonkBndrT m)
forall a. IO a -> ZonkBndrT m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (ZonkBndrT m)
forall (m :: * -> *) a. MonadIO m => IO a -> ZonkBndrT m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> ZonkBndrT m a
liftIO :: forall a. IO a -> ZonkBndrT m a
MonadIO, Monad (ZonkBndrT m)
Monad (ZonkBndrT m) =>
(forall a. (a -> ZonkBndrT m a) -> ZonkBndrT m a)
-> MonadFix (ZonkBndrT m)
forall a. (a -> ZonkBndrT m a) -> ZonkBndrT m a
forall (m :: * -> *).
Monad m =>
(forall a. (a -> m a) -> m a) -> MonadFix m
forall (m :: * -> *). MonadIO m => Monad (ZonkBndrT m)
forall (m :: * -> *) a.
MonadIO m =>
(a -> ZonkBndrT m a) -> ZonkBndrT m a
$cmfix :: forall (m :: * -> *) a.
MonadIO m =>
(a -> ZonkBndrT m a) -> ZonkBndrT m a
mfix :: forall a. (a -> ZonkBndrT m a) -> ZonkBndrT m a
MonadFix)
via Codensity (ZonkT m)
runZonkBndrT :: ZonkBndrT m a -> forall r. (a -> ZonkT m r) -> ZonkT m r
runZonkBndrT :: forall (m :: * -> *) a.
ZonkBndrT m a -> forall r. (a -> ZonkT m r) -> ZonkT m r
runZonkBndrT (ZonkBndrT forall r. (a -> ZonkT m r) -> ZonkT m r
k) a -> ZonkT m r
f = (a -> ZonkT m r) -> ZonkT m r
forall r. (a -> ZonkT m r) -> ZonkT m r
k ((a -> ZonkT m r) -> a -> ZonkT m r
forall a b. (a -> b) -> a -> b
oneShot a -> ZonkT m r
f)
{-# INLINE runZonkBndrT #-}
noBinders :: Monad m => ZonkT m a -> ZonkBndrT m a
noBinders :: forall (m :: * -> *) a. Monad m => ZonkT m a -> ZonkBndrT m a
noBinders ZonkT m a
z = Codensity (ZonkT m) a -> ZonkBndrT m a
forall a b. Coercible a b => a -> b
coerce (Codensity (ZonkT m) a -> ZonkBndrT m a)
-> Codensity (ZonkT m) a -> ZonkBndrT m a
forall a b. (a -> b) -> a -> b
$ ZonkT m a -> Codensity (ZonkT m) a
forall (m :: * -> *) a. Monad m => m a -> Codensity m a
toCodensity ZonkT m a
z
{-# INLINE noBinders #-}
don'tBind :: Monad m => ZonkBndrT m a -> ZonkT m a
don'tBind :: forall (m :: * -> *) a. Monad m => ZonkBndrT m a -> ZonkT m a
don'tBind (ZonkBndrT forall r. (a -> ZonkT m r) -> ZonkT m r
k) = Codensity (ZonkT m) a -> ZonkT m a
forall (m :: * -> *) a. Monad m => Codensity m a -> m a
fromCodensity ((forall r. (a -> ZonkT m r) -> ZonkT m r) -> Codensity (ZonkT m) a
forall (m :: * -> *) a.
(forall r. (a -> m r) -> m r) -> Codensity m a
Codensity (a -> ZonkT m r) -> ZonkT m r
forall r. (a -> ZonkT m r) -> ZonkT m r
k)
{-# INLINE don'tBind #-}
initZonkEnv :: MonadIO m => ZonkFlexi -> ZonkT m b -> m b
initZonkEnv :: forall (m :: * -> *) b. MonadIO m => ZonkFlexi -> ZonkT m b -> m b
initZonkEnv ZonkFlexi
flexi ZonkT m b
thing_inside
= do { mtv_env_ref <- IO (IORef (TyVarEnv Type)) -> m (IORef (TyVarEnv Type))
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (IORef (TyVarEnv Type)) -> m (IORef (TyVarEnv Type)))
-> IO (IORef (TyVarEnv Type)) -> m (IORef (TyVarEnv Type))
forall a b. (a -> b) -> a -> b
$ TyVarEnv Type -> IO (IORef (TyVarEnv Type))
forall a. a -> IO (IORef a)
newIORef TyVarEnv Type
forall a. VarEnv a
emptyVarEnv
; let ze = ZonkEnv { ze_flexi :: ZonkFlexi
ze_flexi = ZonkFlexi
flexi
, ze_tv_env :: TyCoVarEnv TyCoVar
ze_tv_env = TyCoVarEnv TyCoVar
forall a. VarEnv a
emptyVarEnv
, ze_id_env :: TyCoVarEnv TyCoVar
ze_id_env = TyCoVarEnv TyCoVar
forall a. VarEnv a
emptyVarEnv
, ze_meta_tv_env :: IORef (TyVarEnv Type)
ze_meta_tv_env = IORef (TyVarEnv Type)
mtv_env_ref }
; runZonkT thing_inside ze }
{-# INLINEABLE initZonkEnv #-}
nestZonkEnv :: (ZonkEnv -> ZonkEnv) -> ZonkBndrT m ()
nestZonkEnv :: forall (m :: * -> *). (ZonkEnv -> ZonkEnv) -> ZonkBndrT m ()
nestZonkEnv ZonkEnv -> ZonkEnv
f = (forall r. (() -> ZonkT m r) -> ZonkT m r) -> ZonkBndrT m ()
forall (m :: * -> *) a.
(forall r. (a -> ZonkT m r) -> ZonkT m r) -> ZonkBndrT m a
ZonkBndrT ((forall r. (() -> ZonkT m r) -> ZonkT m r) -> ZonkBndrT m ())
-> (forall r. (() -> ZonkT m r) -> ZonkT m r) -> ZonkBndrT m ()
forall a b. (a -> b) -> a -> b
$ \ () -> ZonkT m r
k ->
case () -> ZonkT m r
k () of
ZonkT ZonkEnv -> m r
g -> (ZonkEnv -> m r) -> ZonkT m r
forall (m :: * -> *) a. (ZonkEnv -> m a) -> ZonkT m a
ZonkT (ZonkEnv -> m r
g (ZonkEnv -> m r) -> (ZonkEnv -> ZonkEnv) -> ZonkEnv -> m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonkEnv -> ZonkEnv
f)
{-# INLINE nestZonkEnv #-}
getZonkEnv :: Monad m => ZonkT m ZonkEnv
getZonkEnv :: forall (m :: * -> *). Monad m => ZonkT m ZonkEnv
getZonkEnv = (ZonkEnv -> m ZonkEnv) -> ZonkT m ZonkEnv
forall (m :: * -> *) a. (ZonkEnv -> m a) -> ZonkT m a
ZonkT ZonkEnv -> m ZonkEnv
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
{-# INLINE getZonkEnv #-}
extendIdZonkEnvRec :: [Var] -> ZonkBndrT m ()
extendIdZonkEnvRec :: forall (m :: * -> *). [TyCoVar] -> ZonkBndrT m ()
extendIdZonkEnvRec [TyCoVar]
ids =
(ZonkEnv -> ZonkEnv) -> ZonkBndrT m ()
forall (m :: * -> *). (ZonkEnv -> ZonkEnv) -> ZonkBndrT m ()
nestZonkEnv ((ZonkEnv -> ZonkEnv) -> ZonkBndrT m ())
-> (ZonkEnv -> ZonkEnv) -> ZonkBndrT m ()
forall a b. (a -> b) -> a -> b
$
\ ze :: ZonkEnv
ze@(ZonkEnv { ze_id_env :: ZonkEnv -> TyCoVarEnv TyCoVar
ze_id_env = TyCoVarEnv TyCoVar
id_env }) ->
ZonkEnv
ze { ze_id_env = extendVarEnvList id_env [(id,id) | id <- ids] }
extendZonkEnv :: [Var] -> ZonkBndrT m ()
extendZonkEnv :: forall (m :: * -> *). [TyCoVar] -> ZonkBndrT m ()
extendZonkEnv [TyCoVar]
vars =
(ZonkEnv -> ZonkEnv) -> ZonkBndrT m ()
forall (m :: * -> *). (ZonkEnv -> ZonkEnv) -> ZonkBndrT m ()
nestZonkEnv ((ZonkEnv -> ZonkEnv) -> ZonkBndrT m ())
-> (ZonkEnv -> ZonkEnv) -> ZonkBndrT m ()
forall a b. (a -> b) -> a -> b
$
\ ze :: ZonkEnv
ze@(ZonkEnv { ze_tv_env :: ZonkEnv -> TyCoVarEnv TyCoVar
ze_tv_env = TyCoVarEnv TyCoVar
tyco_env, ze_id_env :: ZonkEnv -> TyCoVarEnv TyCoVar
ze_id_env = TyCoVarEnv TyCoVar
id_env }) ->
ZonkEnv
ze { ze_tv_env = extendVarEnvList tyco_env [(tv,tv) | tv <- tycovars]
, ze_id_env = extendVarEnvList id_env [(id,id) | id <- ids] }
where
([TyCoVar]
tycovars, [TyCoVar]
ids) = (TyCoVar -> Bool) -> [TyCoVar] -> ([TyCoVar], [TyCoVar])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition TyCoVar -> Bool
isTyCoVar [TyCoVar]
vars
extendIdZonkEnv :: Var -> ZonkBndrT m ()
extendIdZonkEnv :: forall (m :: * -> *). TyCoVar -> ZonkBndrT m ()
extendIdZonkEnv TyCoVar
id =
(ZonkEnv -> ZonkEnv) -> ZonkBndrT m ()
forall (m :: * -> *). (ZonkEnv -> ZonkEnv) -> ZonkBndrT m ()
nestZonkEnv ((ZonkEnv -> ZonkEnv) -> ZonkBndrT m ())
-> (ZonkEnv -> ZonkEnv) -> ZonkBndrT m ()
forall a b. (a -> b) -> a -> b
$
\ ze :: ZonkEnv
ze@(ZonkEnv { ze_id_env :: ZonkEnv -> TyCoVarEnv TyCoVar
ze_id_env = TyCoVarEnv TyCoVar
id_env }) ->
ZonkEnv
ze { ze_id_env = extendVarEnv id_env id id }
extendTyZonkEnv :: TyVar -> ZonkBndrT m ()
extendTyZonkEnv :: forall (m :: * -> *). TyCoVar -> ZonkBndrT m ()
extendTyZonkEnv TyCoVar
tv =
(ZonkEnv -> ZonkEnv) -> ZonkBndrT m ()
forall (m :: * -> *). (ZonkEnv -> ZonkEnv) -> ZonkBndrT m ()
nestZonkEnv ((ZonkEnv -> ZonkEnv) -> ZonkBndrT m ())
-> (ZonkEnv -> ZonkEnv) -> ZonkBndrT m ()
forall a b. (a -> b) -> a -> b
$
\ ze :: ZonkEnv
ze@(ZonkEnv { ze_tv_env :: ZonkEnv -> TyCoVarEnv TyCoVar
ze_tv_env = TyCoVarEnv TyCoVar
ty_env }) ->
ZonkEnv
ze { ze_tv_env = extendVarEnv ty_env tv tv }
setZonkType :: ZonkFlexi -> ZonkT m a -> ZonkT m a
setZonkType :: forall (m :: * -> *) a. ZonkFlexi -> ZonkT m a -> ZonkT m a
setZonkType ZonkFlexi
flexi (ZonkT ZonkEnv -> m a
f) = (ZonkEnv -> m a) -> ZonkT m a
forall (m :: * -> *) a. (ZonkEnv -> m a) -> ZonkT m a
ZonkT ((ZonkEnv -> m a) -> ZonkT m a) -> (ZonkEnv -> m a) -> ZonkT m a
forall a b. (a -> b) -> a -> b
$ \ ZonkEnv
ze ->
ZonkEnv -> m a
f (ZonkEnv -> m a) -> ZonkEnv -> m a
forall a b. (a -> b) -> a -> b
$ ZonkEnv
ze { ze_flexi = flexi }