diff options
author | Joe Crayne <joe@jerkface.net> | 2019-08-10 07:02:30 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-08-10 07:02:30 -0400 |
commit | ab75b833bbc6e53b6f91fb9faf08508e1c26cff2 (patch) | |
tree | 5495288817732a39307b1f862e8b4903b63df6fd /packages | |
parent | 3834085a322dc0e0c9672c936fc126e2e488162a (diff) |
consolidate unsafePerformIO blocks.
Diffstat (limited to 'packages')
-rw-r--r-- | packages/base/src/Internal/Specialized.hs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/packages/base/src/Internal/Specialized.hs b/packages/base/src/Internal/Specialized.hs index d840434..c85d44f 100644 --- a/packages/base/src/Internal/Specialized.hs +++ b/packages/base/src/Internal/Specialized.hs | |||
@@ -129,11 +129,12 @@ modint :: forall t n. (Read t, Storable t, Integral t) => TypeRep n -> IntegralR | |||
129 | modint r = IntegralRep i2f i2fM f2i f2iM unMod (n `seq` Just n) | 129 | modint r = IntegralRep i2f i2fM f2i f2iM unMod (n `seq` Just n) |
130 | where | 130 | where |
131 | -- n = withTypeable r $ fromIntegral . natVal $ (undefined :: Proxy n) -- If only.. | 131 | -- n = withTypeable r $ fromIntegral . natVal $ (undefined :: Proxy n) -- If only.. |
132 | n = case unsafePerformIO $ readIORef cachedNat of | 132 | n = unsafePerformIO $ do |
133 | SomeNat c -> withTypeable r $ | 133 | SomeNat c <- readIORef cachedNat |
134 | withTypeable r $ do | ||
134 | case withTypes c r <$> eqT of | 135 | case withTypes c r <$> eqT of |
135 | Just Refl -> fromIntegral $ natVal c | 136 | Just Refl -> return $ fromIntegral $ natVal c |
136 | _ -> unsafePerformIO $ do | 137 | _ -> do |
137 | let newnat = read . show $ r -- XXX: Hack to get nat value from Type.Reflection | 138 | let newnat = read . show $ r -- XXX: Hack to get nat value from Type.Reflection |
138 | case someNatVal $ fromIntegral newnat of | 139 | case someNatVal $ fromIntegral newnat of |
139 | Just somenat@(SomeNat nt) -> nt `seq` writeIORef cachedNat somenat | 140 | Just somenat@(SomeNat nt) -> nt `seq` writeIORef cachedNat somenat |