on main help sign in
Fix segfault in 'toList' (#65)
45d30e7Vladislav Zavialov
shell.nix+1−1
@@ -4,7 +4,7 @@ with import <nixpkgs> { };
4stdenv.mkDerivation rec {
4stdenv.mkDerivation rec {
5 name = "typerep-map";
5 name = "typerep-map";
6 buildInputs = [
6 buildInputs = [
7− haskell.compiler.ghc843
7+ haskell.compiler.ghc844
8 pkgs.cabal-install
8 pkgs.cabal-install
9 ];
9 ];
10}
10}
src/Data/TypeRepMap/Internal.hs+4−1
@@ -345,6 +345,9 @@ data WrapTypeable f where
345instance Show (WrapTypeable f) where
345instance Show (WrapTypeable f) where
346 show (WrapTypeable (_ :: f a)) = show $ calcFp @a
346 show (WrapTypeable (_ :: f a)) = show $ calcFp @a
347
347
348+wrapTypeable :: TypeRep a -> f a -> WrapTypeable f
349+wrapTypeable tr = withTypeable tr WrapTypeable
350+
348{- |
351{- |
349
352
350prop> fromList . toList == 'id'
353prop> fromList . toList == 'id'
@@ -375,7 +378,7 @@ instance IsList (TypeRepMap f) where
375 toList = map toWrapTypeable . toTriples
378 toList = map toWrapTypeable . toTriples
376 where
379 where
377 toWrapTypeable :: (Fingerprint, Any, Any) -> WrapTypeable f
380 toWrapTypeable :: (Fingerprint, Any, Any) -> WrapTypeable f
378− toWrapTypeable (_, an, k) = withTypeable (unsafeCoerce k) $ fromAny an
381+ toWrapTypeable (_, an, k) = wrapTypeable (unsafeCoerce k) (fromAny an)
379
382
380calcFp :: forall a . Typeable a => Fingerprint
383calcFp :: forall a . Typeable a => Fingerprint
381calcFp = typeRepFingerprint $ typeRep @a
384calcFp = typeRepFingerprint $ typeRep @a