summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-08-10 05:59:45 -0400
committerJoe Crayne <joe@jerkface.net>2019-08-10 06:01:19 -0400
commit142d9cb898f284860c9669d3473aeacc79171088 (patch)
treefaec0100ece9b3e797d23edb9dd24373944f360d
parent81b635594934ed0155fbd3bf544deb544627868a (diff)
Stricter nat cache.
-rw-r--r--packages/base/src/Internal/Specialized.hs6
1 files 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
104 , rep2i :: Vector a -> Vector t 104 , rep2i :: Vector a -> Vector t
105 , rep2iM :: Matrix a -> Matrix t 105 , rep2iM :: Matrix a -> Matrix t
106 , rep2one :: a -> t 106 , rep2one :: a -> t
107 , modulo :: Maybe t 107 , modulo :: !(Maybe t)
108 } 108 }
109 109
110instance Show (IntegralRep t a) where 110instance Show (IntegralRep t a) where
@@ -126,7 +126,7 @@ withTypes :: p (a::k) -> q (b::h) -> f a b -> f a b
126withTypes _ _ = id 126withTypes _ _ = id
127 127
128modint :: forall t n. (Read t, Storable t, Integral t) => TypeRep n -> IntegralRep t (Mod n t) 128modint :: forall t n. (Read t, Storable t, Integral t) => TypeRep n -> IntegralRep t (Mod n t)
129modint r = IntegralRep i2f i2fM f2i f2iM unMod (Just n) 129modint 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 = case unsafePerformIO $ readIORef cachedNat of
@@ -136,7 +136,7 @@ modint r = IntegralRep i2f i2fM f2i f2iM unMod (Just n)
136 _ -> unsafePerformIO $ do 136 _ -> unsafePerformIO $ do
137 let newnat = read . show $ r -- XXX: Hack to get nat value from Type.Reflection 137 let newnat = read . show $ r -- XXX: Hack to get nat value from Type.Reflection
138 case someNatVal $ fromIntegral newnat of 138 case someNatVal $ fromIntegral newnat of
139 Just somenat -> writeIORef cachedNat somenat 139 Just somenat@(SomeNat nt) -> nt `seq` writeIORef cachedNat somenat
140 _ -> return () 140 _ -> return ()
141 return newnat 141 return newnat
142 142