rank1dynamic 0.3.1.1 → 0.3.2.0
raw patch · 4 files changed
+52/−21 lines, 4 filesdep −ghc-primdep ~basedep ~binaryPVP ok
version bump matches the API change (PVP)
Dependencies removed: ghc-prim
Dependency ranges changed: base, binary
API changes (from Hackage documentation)
+ Data.Rank1Dynamic: unsafeToDynamic :: TypeRep -> a -> Dynamic
Files
- ChangeLog +9/−0
- rank1dynamic.cabal +4/−5
- src/Data/Rank1Dynamic.hs +11/−1
- src/Data/Rank1Typeable.hs +28/−15
ChangeLog view
@@ -1,3 +1,12 @@+2016-02-18 Facundo Domínguez <facundo.dominguez@tweag.io> 0.3.2.0++* Stop testing ghc-7.4 and test ghc-7.10.+* Add unsafeToDynamic.++2016-01-25 Facundo Domínguez <facundo.dominguez@tweag.io> 0.3.1.1++* Push HUnit upper bound.+ 2015-06-15 Facundo Domínguez <facundo.dominguez@tweag.io> 0.2.1.0 * Loosen upper bound of ghc-prim.
rank1dynamic.cabal view
@@ -1,9 +1,9 @@ Name: rank1dynamic-Version: 0.3.1.1+Version: 0.3.2.0 Synopsis: Like Data.Dynamic/Data.Typeable but with support for rank-1 polymorphic types-Description: "Data.Typeable" and "Data.Dynamic" only support monomorphic types. +Description: "Data.Typeable" and "Data.Dynamic" only support monomorphic types. In this package we provide similar functionality but with- support for rank-1 polymorphic types. + support for rank-1 polymorphic types. Homepage: http://haskell-distributed.github.com License: BSD3 License-File: LICENSE@@ -24,8 +24,7 @@ Exposed-Modules: Data.Rank1Dynamic, Data.Rank1Typeable Build-Depends: base >= 4.4 && < 5,- ghc-prim >= 0.2 && < 0.5,- binary >= 0.5 && < 0.8+ binary >= 0.5 && < 0.9 HS-Source-Dirs: src GHC-Options: -Wall Extensions: EmptyDataDecls,
src/Data/Rank1Dynamic.hs view
@@ -78,9 +78,10 @@ , TypeError , dynTypeRep , dynApply+ , unsafeToDynamic ) where -import qualified GHC.Prim as GHC (Any)+import qualified GHC.Exts as GHC (Any) import Data.Rank1Typeable ( Typeable , TypeRep@@ -100,6 +101,15 @@ -- | Introduce a dynamic value toDynamic :: Typeable a => a -> Dynamic toDynamic x = Dynamic (typeOf x) (unsafeCoerce x)++-- | Construct a dynamic value with a user-supplied type rep+--+-- This function is unsafe because we have no way of verifying that the+-- provided type representation matches the value.+--+-- Since 0.3.2.0.+unsafeToDynamic :: TypeRep -> a -> Dynamic+unsafeToDynamic typ x = Dynamic typ (unsafeCoerce x) -- | Eliminate a dynamic value fromDynamic :: Typeable a => Dynamic -> Either TypeError a
src/Data/Rank1Typeable.hs view
@@ -101,10 +101,20 @@ import Control.Applicative ((<$>)) import Data.List (intersperse, isPrefixOf) import Data.Maybe (fromMaybe)-import Data.Typeable (Typeable, mkTyCon3)-import Data.Typeable.Internal (listTc, funTc, TyCon(TyCon), tyConName)+import Data.Typeable+ ( Typeable+ , TyCon+ , mkTyCon3+ , tyConPackage+ , tyConModule+ , tyConName+ )+#if MIN_VERSION_base(4,9,0)+import Data.Typeable.Internal (tcList, tcFun)+#else+import Data.Typeable.Internal (listTc, funTc)+#endif import Data.Binary (Binary(get, put))-import GHC.Fingerprint.Type (Fingerprint(..)) import qualified Data.Typeable as Typeable ( TypeRep , typeOf@@ -112,6 +122,13 @@ , mkTyConApp ) ++#if !MIN_VERSION_base(4,9,0)+tcList, tcFun :: TyCon+tcList = listTc+tcFun = funTc+#endif+ -------------------------------------------------------------------------------- -- The basic type -- --------------------------------------------------------------------------------@@ -137,21 +154,17 @@ -- Binary instance for 'TypeRep', avoiding orphan instances instance Binary TypeRep where- put (splitTyConApp -> (TyCon (Fingerprint hi lo) package modul name, ts)) = do- put hi- put lo- put package- put modul- put name+ put (splitTyConApp -> (tc, ts)) = do+ put $ tyConPackage tc+ put $ tyConModule tc+ put $ tyConName tc put ts get = do- hi <- get- lo <- get package <- get modul <- get name <- get ts <- get- return $ mkTyConApp (TyCon (Fingerprint hi lo) package modul name) ts+ return $ mkTyConApp (mkTyCon3 package modul name) ts -- | The type representation of any 'Typeable' term typeOf :: Typeable a => a -> TypeRep@@ -233,7 +246,7 @@ funResultTy :: TypeRep -> TypeRep -> Either TypeError TypeRep funResultTy t1 t2 = do let anyTy = mkTypVar $ typeOf (undefined :: V0)- s <- unify (alphaRename "f" t1) $ mkTyConApp funTc [alphaRename "x" t2, anyTy]+ s <- unify (alphaRename "f" t1) $ mkTyConApp tcFun [alphaRename "x" t2, anyTy] return $ normalize $ subst s anyTy --------------------------------------------------------------------------------@@ -324,9 +337,9 @@ case tys of [] -> showsPrec p tycon [anyIdx -> Just i] | tycon == typVar -> showString "ANY" . showIdx i- [x] | tycon == listTc ->+ [x] | tycon == tcList -> showChar '[' . shows x . showChar ']'- [a,r] | tycon == funTc ->+ [a,r] | tycon == tcFun -> showParen (p > 8) $ showsPrec 9 a . showString " -> " . showsPrec 8 r