on master help sign in
Remove AllowAmbiguousTypes from Effectful.Internal.Env
commit7527aa4440ea22fe4bf14e44fa25a291c23ec46a authorAndrzej Rybczak <andrzej@rybczak.net> dateFri 13 Aug 2021, 17:20 (5 years ago) parent2e43b3d
1 file changed+8−9
effectful-core/src/Effectful/Internal/Env.hs+8−9
effectful-core/src/Effectful/Internal/Env.hs+8−9
@@ -1,4 +1,3 @@
1−{-# LANGUAGE AllowAmbiguousTypes #-}
21{-# OPTIONS_HADDOCK not-home #-}
32-- | The environment for the 'Effectful.Internal.Monad.Eff' monad.
43--
@@ -408,7 +407,7 @@ getEnv
408407 => Env es
409408 -> IO (handler e)
410409getEnv env = do
411− (i, es) <- getLocation @e env
410+ (i, es) <- getLocation (reifyIndex @e @es) env
412411 fromAny <$> readSmallArray es i
413412
414413-- | Replace the data type in the environment with a new value (in place).
@@ -418,7 +417,7 @@ putEnv
418417 -> handler e
419418 -> IO ()
420419putEnv env e = do
421− (i, es) <- getLocation @e env
420+ (i, es) <- getLocation (reifyIndex @e @es) env
422421 e `seq` writeSmallArray es i (toAny e)
423422
424423-- | Modify the data type in the environment (in place) and return a value.
@@ -428,7 +427,7 @@ stateEnv
428427 -> (handler e -> (a, handler e))
429428 -> IO a
430429stateEnv env f = do
431− (i, es) <- getLocation @e env
430+ (i, es) <- getLocation (reifyIndex @e @es) env
432431 (a, e) <- f . fromAny <$> readSmallArray es i
433432 e `seq` writeSmallArray es i (toAny e)
434433 pure a
@@ -440,7 +439,7 @@ modifyEnv
440439 -> (handler e -> handler e)
441440 -> IO ()
442441modifyEnv env f = do
443− (i, es) <- getLocation @e env
442+ (i, es) <- getLocation (reifyIndex @e @es) env
444443 e <- f . fromAny <$> readSmallArray es i
445444 e `seq` writeSmallArray es i (toAny e)
446445
@@ -458,10 +457,10 @@ emptyEnvRef = do
458457
459458-- | Determine location of the data type in the environment.
460459getLocation
461− :: forall e es. e :> es
462− => Env es
460+ :: Int
461+ -> Env es
463462 -> IO (Int, SmallMutableArray RealWorld Any)
464−getLocation (Env fork ref _) = do
463+getLocation ixE (Env fork ref _) = do
465464 EnvRef n es _ <- readIORef ref
466465 -- Optimized for the common access pattern:
467466 --
@@ -492,7 +491,7 @@ getLocation (Env fork ref _) = do
492491 else go es i forks
493492
494493 ix :: Int -> Int
495− ix n = n - reifyIndex @e @es - 1
494+ ix n = n - ixE - 1
496495
497496toAny :: a -> Any
498497toAny = unsafeCoerce