From 142d9cb898f284860c9669d3473aeacc79171088 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sat, 10 Aug 2019 05:59:45 -0400 Subject: Stricter nat cache. --- packages/base/src/Internal/Specialized.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/base/src/Internal/Specialized.hs b/packages/base/src/Internal/Specialized.hs index 5f89779..9a68ad5 100644 --- a/packages/base/src/Internal/Specialized.hs +++ b/packages/base/src/Internal/Specialized.hs @@ -104,7 +104,7 @@ data IntegralRep t a = IntegralRep , rep2i :: Vector a -> Vector t , rep2iM :: Matrix a -> Matrix t , rep2one :: a -> t - , modulo :: Maybe t + , modulo :: !(Maybe t) } instance Show (IntegralRep t a) where @@ -126,7 +126,7 @@ withTypes :: p (a::k) -> q (b::h) -> f a b -> f a b withTypes _ _ = id modint :: forall t n. (Read t, Storable t, Integral t) => TypeRep n -> IntegralRep t (Mod n t) -modint r = IntegralRep i2f i2fM f2i f2iM unMod (Just n) +modint r = IntegralRep i2f i2fM f2i f2iM unMod (n `seq` Just n) where -- n = withTypeable r $ fromIntegral . natVal $ (undefined :: Proxy n) -- If only.. n = case unsafePerformIO $ readIORef cachedNat of @@ -136,7 +136,7 @@ modint r = IntegralRep i2f i2fM f2i f2iM unMod (Just n) _ -> unsafePerformIO $ do let newnat = read . show $ r -- XXX: Hack to get nat value from Type.Reflection case someNatVal $ fromIntegral newnat of - Just somenat -> writeIORef cachedNat somenat + Just somenat@(SomeNat nt) -> nt `seq` writeIORef cachedNat somenat _ -> return () return newnat -- cgit v1.2.3