on master help sign in
Remove AllowAmbiguousTypes from Effectful.Internal.Env
7527aa4Andrzej Rybczak
effectful-core/src/Effectful/Internal/Env.hs+8−9
@@ -1,4 +1,3 @@
1−{-# LANGUAGE AllowAmbiguousTypes #-}
2{-# OPTIONS_HADDOCK not-home #-}
1{-# OPTIONS_HADDOCK not-home #-}
3-- | The environment for the 'Effectful.Internal.Monad.Eff' monad.
2-- | The environment for the 'Effectful.Internal.Monad.Eff' monad.
4--
3--
@@ -408,7 +407,7 @@ getEnv
408 => Env es
407 => Env es
409 -> IO (handler e)
408 -> IO (handler e)
410getEnv env = do
409getEnv env = do
411− (i, es) <- getLocation @e env
410+ (i, es) <- getLocation (reifyIndex @e @es) env
412 fromAny <$> readSmallArray es i
411 fromAny <$> readSmallArray es i
413
412
414-- | Replace the data type in the environment with a new value (in place).
413-- | Replace the data type in the environment with a new value (in place).
@@ -418,7 +417,7 @@ putEnv
418 -> handler e
417 -> handler e
419 -> IO ()
418 -> IO ()
420putEnv env e = do
419putEnv env e = do
421− (i, es) <- getLocation @e env
420+ (i, es) <- getLocation (reifyIndex @e @es) env
422 e `seq` writeSmallArray es i (toAny e)
421 e `seq` writeSmallArray es i (toAny e)
423
422
424-- | Modify the data type in the environment (in place) and return a value.
423-- | Modify the data type in the environment (in place) and return a value.
@@ -428,7 +427,7 @@ stateEnv
428 -> (handler e -> (a, handler e))
427 -> (handler e -> (a, handler e))
429 -> IO a
428 -> IO a
430stateEnv env f = do
429stateEnv env f = do
431− (i, es) <- getLocation @e env
430+ (i, es) <- getLocation (reifyIndex @e @es) env
432 (a, e) <- f . fromAny <$> readSmallArray es i
431 (a, e) <- f . fromAny <$> readSmallArray es i
433 e `seq` writeSmallArray es i (toAny e)
432 e `seq` writeSmallArray es i (toAny e)
434 pure a
433 pure a
@@ -440,7 +439,7 @@ modifyEnv
440 -> (handler e -> handler e)
439 -> (handler e -> handler e)
441 -> IO ()
440 -> IO ()
442modifyEnv env f = do
441modifyEnv env f = do
443− (i, es) <- getLocation @e env
442+ (i, es) <- getLocation (reifyIndex @e @es) env
444 e <- f . fromAny <$> readSmallArray es i
443 e <- f . fromAny <$> readSmallArray es i
445 e `seq` writeSmallArray es i (toAny e)
444 e `seq` writeSmallArray es i (toAny e)
446
445
@@ -458,10 +457,10 @@ emptyEnvRef = do
458
457
459-- | Determine location of the data type in the environment.
458-- | Determine location of the data type in the environment.
460getLocation
459getLocation
461− :: forall e es. e :> es
460+ :: Int
462− => Env es
461+ -> Env es
463 -> IO (Int, SmallMutableArray RealWorld Any)
462 -> IO (Int, SmallMutableArray RealWorld Any)
464−getLocation (Env fork ref _) = do
463+getLocation ixE (Env fork ref _) = do
465 EnvRef n es _ <- readIORef ref
464 EnvRef n es _ <- readIORef ref
466 -- Optimized for the common access pattern:
465 -- Optimized for the common access pattern:
467 --
466 --
@@ -492,7 +491,7 @@ getLocation (Env fork ref _) = do
492 else go es i forks
491 else go es i forks
493
492
494 ix :: Int -> Int
493 ix :: Int -> Int
495− ix n = n - reifyIndex @e @es - 1
494+ ix n = n - ixE - 1
496
495
497toAny :: a -> Any
496toAny :: a -> Any
498toAny = unsafeCoerce
497toAny = unsafeCoerce