packages feed

th-lift-instances 0.1.11 → 0.1.12

raw patch · 5 files changed

+198/−59 lines, 5 filesdep +natsdep +semigroupsdep −th-liftdep ~template-haskellPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: nats, semigroups

Dependencies removed: th-lift

Dependency ranges changed: template-haskell

API changes (from Hackage documentation)

- Instances.TH.Lift: instance Language.Haskell.TH.Syntax.Lift a0 => Language.Haskell.TH.Syntax.Lift (Data.Tree.Tree a0)
+ Instances.TH.Lift: instance Language.Haskell.TH.Syntax.Lift Data.Void.Void
+ Instances.TH.Lift: instance Language.Haskell.TH.Syntax.Lift a => Language.Haskell.TH.Syntax.Lift (Data.List.NonEmpty.NonEmpty a)
+ Instances.TH.Lift: instance Language.Haskell.TH.Syntax.Lift a => Language.Haskell.TH.Syntax.Lift (Data.Tree.Tree a)

Files

.travis.yml view
@@ -13,30 +13,39 @@ script: travis/script.sh matrix:   include:-    - env: GHCVER=7.0.4 CABALVER=1.16-      compiler: ": #GHC 7.0.4"-      addons: {apt: {packages: [cabal-install-1.16, ghc-7.0.4, alex-3.1.4, happy-1.19.5], sources: [hvr-ghc]}}-    - env: GHCVER=7.2.2 CABALVER=1.16-      compiler: ": #GHC 7.2.2"-      addons: {apt: {packages: [cabal-install-1.16, ghc-7.2.2, alex-3.1.4, happy-1.19.5], sources: [hvr-ghc]}}-    - env: GHCVER=7.4.2 CABALVER=1.16-      compiler: ": #GHC 7.4.2"-      addons: {apt: {packages: [cabal-install-1.16, ghc-7.4.2, alex-3.1.4, happy-1.19.5], sources: [hvr-ghc]}}-    - env: GHCVER=7.6.3 CABALVER=1.18-      compiler: ": #GHC 7.6.3"-      addons: {apt: {packages: [cabal-install-1.18, ghc-7.6.3, alex-3.1.4, happy-1.19.5], sources: [hvr-ghc]}}-    - env: GHCVER=7.8.4 CABALVER=1.18-      compiler: ": #GHC 7.8.4"-      addons: {apt: {packages: [cabal-install-1.18, ghc-7.8.4, alex-3.1.4, happy-1.19.5], sources: [hvr-ghc]}}-    - env: GHCVER=7.10.3 CABALVER=1.22 ROOT=1-      compiler: ": #GHC 7.10.3"-      addons: {apt: {packages: [cabal-install-1.22, ghc-7.10.3, alex-3.1.4, happy-1.19.5], sources: [hvr-ghc]}}-    - env: GHCVER=8.0.1 CABALVER=1.24-      compiler: ": #GHC 8.0.1"+    - env: GHCVER=7.0.4 CABALVER=1.18+      compiler: ghc-7.0.4+      addons: {apt: {packages: [cabal-install-1.18, ghc-7.0.4, alex-3.1.4, happy-1.19.5], sources: [hvr-ghc]}}+    - env: GHCVER=7.2.2 CABALVER=1.18+      compiler: ghc-7.2.2+      addons: {apt: {packages: [cabal-install-1.18, ghc-7.2.2, alex-3.1.4, happy-1.19.5], sources: [hvr-ghc]}}+    - env: GHCVER=7.4.2 CABALVER=1.24+      compiler: ghc-7.4.2+      addons: {apt: {packages: [cabal-install-1.24, ghc-7.4.2, alex-3.1.4, happy-1.19.5], sources: [hvr-ghc]}}+    - env: GHCVER=7.6.3 CABALVER=1.24+      compiler: ghc-7.6.3+      addons: {apt: {packages: [cabal-install-1.24, ghc-7.6.3, alex-3.1.4, happy-1.19.5], sources: [hvr-ghc]}}+    - env: GHCVER=7.8.4 CABALVER=1.24+      compiler: ghc-7.8.4+      addons: {apt: {packages: [cabal-install-1.24, ghc-7.8.4, alex-3.1.4, happy-1.19.5], sources: [hvr-ghc]}}+    - env: GHCVER=7.10.3 CABALVER=1.24+      compiler: ghc-7.10.3+      addons: {apt: {packages: [cabal-install-1.24, ghc-7.10.3, alex-3.1.4, happy-1.19.5], sources: [hvr-ghc]}}+    - env: GHCVER=8.0.1 CABALVER=1.24 ROOT=1+      compiler: ghc-8.0.1       addons: {apt: {packages: [cabal-install-1.24, ghc-8.0.1, alex-3.1.7, happy-1.19.5], sources: [hvr-ghc]}}+    - env: GHCVER=8.2.2 CABALVER=2.0+      compiler: ghc-8.2.2+      addons: {apt: {packages: [cabal-install-2.0, ghc-8.2.2, alex-3.1.7, happy-1.19.5], sources: [hvr-ghc]}}+    - env: GHCVER=8.4.4 CABALVER=2.2+      compiler: ghc-8.4.4+      addons: {apt: {packages: [cabal-install-2.2, ghc-8.4.4, alex-3.1.7, happy-1.19.5], sources: [hvr-ghc]}}+    - env: GHCVER=8.6.3 CABALVER=2.4+      compiler: ghc-8.6.3+      addons: {apt: {packages: [cabal-install-2.4, ghc-8.6.3, alex-3.1.7, happy-1.19.5], sources: [hvr-ghc]}}     - env: GHCVER=head CABALVER=head ALLOW_NEWER="template-haskell"-      compiler: ": #GHC head"-      addons: {apt: {packages: [cabal-install-head, ghc-head, alex-3.1.4, happy-1.19.5], sources: [hvr-ghc]}}+      compiler: ghc-head+      addons: {apt: {packages: [cabal-install-head, ghc-head, alex-3.1.7, happy-1.19.5], sources: [hvr-ghc]}}   allow_failures:-    - compiler: ": #GHC head"+    - compiler: ghc-head   fast_finish: true
src/Instances/TH/Lift.hs view
@@ -1,5 +1,10 @@ {-# OPTIONS_GHC -fno-warn-orphans #-}-{-# LANGUAGE TemplateHaskell, CPP #-}+{-# LANGUAGE CPP #-}+#if __GLASGOW_HASKELL__ >= 800+{-# LANGUAGE TemplateHaskellQuotes #-}+#else+{-# LANGUAGE TemplateHaskell #-}+#endif module Instances.TH.Lift   ( -- | This module provides orphan instances for the 'Language.Haskell.TH.Syntax.Lift' class from template-haskell. Following is a list of the provided instances.     --@@ -21,6 +26,8 @@     -- |  * 'Word8', 'Word16', 'Word32', 'Word64'     --     --    * 'Int8', 'Int16', 'Int32', 'Int64'+    --+    --    * 'NonEmpty' and 'Void', until provided by @template-haskell-2.15@      -- * Containers (both strict/lazy)     -- |  * 'Data.IntMap.IntMap'@@ -46,18 +53,30 @@    ) where -import Language.Haskell.TH.Lift (deriveLift) import Language.Haskell.TH.Syntax (Lift(..))+import Language.Haskell.TH  import qualified Data.Foldable as F  -- Base #if !MIN_VERSION_template_haskell(2,9,1)-import Language.Haskell.TH import Data.Int import Data.Word #endif +#if !MIN_VERSION_template_haskell(2,10,0)+import Data.Ratio (Ratio)+#endif++#if !MIN_VERSION_template_haskell(2,15,0)+#if MIN_VERSION_base(4,8,0)+import Data.Void (Void, absurd)+#endif+#if MIN_VERSION_base(4,9,0)+import Data.List.NonEmpty (NonEmpty (..))+#endif+#endif+ -- Containers import qualified Data.IntMap as IntMap import qualified Data.IntSet as IntSet@@ -72,13 +91,20 @@  -- ByteString import qualified Data.ByteString as ByteString+import qualified Data.ByteString.Unsafe as ByteString.Unsafe import qualified Data.ByteString.Lazy as ByteString.Lazy+import           System.IO.Unsafe (unsafePerformIO)+#if !MIN_VERSION_template_haskell(2, 8, 0)+import qualified Data.ByteString.Char8 as ByteString.Char8+#endif  -- Vector import qualified Data.Vector as Vector.Boxed import qualified Data.Vector.Primitive as Vector.Primitive import qualified Data.Vector.Storable as Vector.Storable import qualified Data.Vector.Unboxed as Vector.Unboxed++ --------------------------------------------------------------------------------  --------------------------------------------------------------------------------@@ -86,82 +112,136 @@ -- Base  instance Lift Word8 where-  lift x = [| fromInteger $(lift $ toInteger x) :: Word8 |]+  lift x = [| fromInteger x' :: Word8 |] where+    x' = toInteger x  instance Lift Word16 where-  lift x = [| fromInteger $(lift $ toInteger x) :: Word16 |]+  lift x = [| fromInteger x' :: Word16 |] where+    x' = toInteger x  instance Lift Word32 where-  lift x = [| fromInteger $(lift $ toInteger x) :: Word32 |]+  lift x = [| fromInteger x' :: Word32 |] where+    x' = toInteger x  instance Lift Word64 where-  lift x = [| fromInteger $(lift $ toInteger x) :: Word64 |]+  lift x = [| fromInteger x' :: Word64 |] where+    x' = toInteger x  instance Lift Int8 where-  lift x = [| fromInteger $(lift $ toInteger x) :: Int8 |]+  lift x = [| fromInteger x' :: Int8 |] where+    x' = toInteger x  instance Lift Int16 where-  lift x = [| fromInteger $(lift $ toInteger x) :: Int16 |]+  lift x = [| fromInteger x' :: Int16 |] where+    x' = toInteger x  instance Lift Int32 where-  lift x = [| fromInteger $(lift $ toInteger x) :: Int32 |]+  lift x = [| fromInteger x' :: Int32 |] where+    x' = toInteger x  instance Lift Int64 where-  lift x = [| fromInteger $(lift $ toInteger x) :: Int64 |]+  lift x = [| fromInteger x' :: Int64 |] where+    x' = toInteger x  instance Lift Float where-  lift x = [| $(litE $ rationalL $ toRational x) :: Float |]+  lift x = return (LitE (RationalL (toRational x)))  instance Lift Double where-  lift x = [| $(litE $ rationalL $ toRational x) :: Double |]-+  lift x = return (LitE (RationalL (toRational x))) # endif +#if !MIN_VERSION_template_haskell(2,10,0)+instance Lift () where+  lift () = [| () |]++instance Integral a => Lift (Ratio a) where+  lift x = return (LitE (RationalL (toRational x)))+#endif++#if !MIN_VERSION_template_haskell(2,15,0)+#if MIN_VERSION_base(4,8,0)++instance Lift Void where+    lift = absurd++#endif+#if MIN_VERSION_base(4,9,0)+instance Lift a => Lift (NonEmpty a) where+    lift (x :| xs) = [| x :| xs |]+#endif+#endif+ -------------------------------------------------------------------------------- -- Containers instance Lift v => Lift (IntMap.IntMap v) where-  lift m = [| IntMap.fromList $(lift $ IntMap.toList m) |]+  lift m = [| IntMap.fromList m' |] where+    m' = IntMap.toList m  instance Lift IntSet.IntSet where-  lift s = [| IntSet.fromList $(lift $ IntSet.toList s) |]+  lift s = [| IntSet.fromList s' |] where+    s' = IntSet.toList s  instance (Lift k, Lift v) => Lift (Map.Map k v) where-  lift m = [| Map.fromList $(lift $ Map.toList m) |]+  lift m = [| Map.fromList m' |] where+    m' = Map.toList m  instance Lift a => Lift (Sequence.Seq a) where-  lift s = [| Sequence.fromList $(lift $ F.toList s) |]+  lift s = [| Sequence.fromList s' |] where+    s' = F.toList s  instance Lift a => Lift (Set.Set a) where-  lift s = [| Set.fromList $(lift $ Set.toList s) |]+  lift s = [| Set.fromList s' |] where+    s' = Set.toList s -deriveLift ''Tree.Tree+instance Lift a => Lift (Tree.Tree a) where+  lift (Tree.Node x xs) = [| Tree.Node x xs |]  -------------------------------------------------------------------------------- -- Text instance Lift Text.Text where-  lift t = [| Text.pack $(lift $ Text.unpack t) |]+  lift t = [| Text.pack t' |] where+    t' = Text.unpack t  instance Lift Text.Lazy.Text where-  lift t = [| Text.Lazy.pack $(lift $ Text.Lazy.unpack t) |]+  lift t = [| Text.Lazy.pack t' |] where+    t' = Text.Lazy.unpack t  -------------------------------------------------------------------------------- -- ByteString instance Lift ByteString.ByteString where-  lift b = [| ByteString.pack $(lift $ ByteString.unpack b) |]+  -- this is essentially what e.g. file-embed does+  lift b = return $ AppE (VarE 'unsafePerformIO) $+    VarE 'ByteString.Unsafe.unsafePackAddressLen `AppE` l `AppE` b'+    where+      l  = LitE $ IntegerL $ fromIntegral $ ByteString.length b+      b' =+#if MIN_VERSION_template_haskell(2, 8, 0)+        LitE $ StringPrimL $ ByteString.unpack b+#else+        LitE $ StringPrimL $ ByteString.Char8.unpack b+#endif  instance Lift ByteString.Lazy.ByteString where-  lift b = [| ByteString.Lazy.pack $(lift $ ByteString.Lazy.unpack b) |]+  lift lb = do+    b' <- lift b+    return  (VarE 'ByteString.Lazy.fromChunks `AppE` b')+    where+      b = ByteString.Lazy.toChunks lb  -------------------------------------------------------------------------------- -- Vector instance (Vector.Primitive.Prim a, Lift a) => Lift (Vector.Primitive.Vector a) where-  lift v = [| Vector.Primitive.fromList $(lift $ Vector.Primitive.toList v) |]+  lift v = [| Vector.Primitive.fromList v' |] where+    v' = Vector.Primitive.toList v  instance (Vector.Storable.Storable a, Lift a) => Lift (Vector.Storable.Vector a) where-  lift v = [| Vector.Storable.fromList $(lift $ Vector.Storable.toList v) |]+  lift v = [| Vector.Storable.fromList v' |] where+    v' = Vector.Storable.toList v  instance (Vector.Unboxed.Unbox a, Lift a) => Lift (Vector.Unboxed.Vector a) where-  lift v = [| Vector.Unboxed.fromList $(lift $ Vector.Unboxed.toList v) |]+  lift v = [| Vector.Unboxed.fromList v' |] where+    v' = Vector.Unboxed.toList v  instance Lift a => Lift (Vector.Boxed.Vector a) where-  lift v = [| Vector.Boxed.fromList $(lift $ Vector.Boxed.toList v) |]+  lift v = [| Vector.Boxed.fromList v' |] where+    v' = Vector.Boxed.toList v
tests/Data.hs view
@@ -2,18 +2,34 @@  import Data.Tree import Data.Word+import Numeric.Natural (Natural)+import Data.List.NonEmpty (NonEmpty (..))+import qualified Data.ByteString as ByteString+import qualified Data.ByteString.Lazy as ByteString.Lazy -mapdata :: [(Int, Int)]-mapdata = [(10, 20), (3,13), (2242,234), (324, 543)]+mapdata :: [(Int, Rational)]+mapdata = [(10, 20), (3,13), (2242,234), (324, 543.3)]  setdata :: [Int] setdata = [1,2,3,4,1,2,6,1,4367,832,23,56] -treedata :: Tree Int-treedata = Node 1 [Node 2 [], Node 5 [], Node 6 [Node 7 [], Node 8 []]]+treedata :: Tree Double+treedata = Node 1 [Node 2 [], Node 5 [], Node 6 [Node 7 [], Node 8.9 []]]  textdata :: String textdata = "Some text! Hello world!"  bytedata :: [Word8] bytedata = map fromIntegral setdata++bigByteString :: ByteString.ByteString+bigByteString = ByteString.pack $ replicate 16384 97 -- 'a'++bigLazyByteString :: ByteString.Lazy.ByteString+bigLazyByteString = ByteString.Lazy.pack $ replicate 16384 98 -- 'b'++nonEmptyNatural :: NonEmpty Natural+nonEmptyNatural = 0 :| [1, 2, 3]++natural1 :: Natural+natural1 = 1
tests/Main.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE TemplateHaskell #-} module Main where @@ -10,6 +11,7 @@ import Language.Haskell.TH.Syntax import System.Exit import Test.QuickCheck.All+import Numeric.Natural (Natural)  import qualified Data.IntMap as IntMap import qualified Data.IntSet as IntSet@@ -60,6 +62,20 @@ prop_double :: Bool prop_double = $(lift (1.1 :: Double)) == (1.1 :: Double) +prop_natural :: Bool+prop_natural = $(lift (1 :: Natural)) == (1 :: Natural)++prop_nonempty_natural :: Bool+#if MIN_VERSION_base(4,10,0)+-- this test will fail, as there aren't yet semigroups with NonEmpty instance+prop_nonempty_natural = $(lift nonEmptyNatural) == nonEmptyNatural+#else+prop_nonempty_natural = True+#endif++prop_unit :: Bool+prop_unit = $(lift ()) == ()+ -------------------------------------------------------------------------------- -- Containers prop_lazy_int_map :: Bool@@ -93,8 +109,14 @@ prop_bytestring :: Bool prop_bytestring = $(lift $ ByteString.pack bytedata) == ByteString.pack bytedata +prop_big_bytestring :: Bool+prop_big_bytestring = $(lift bigByteString) == bigByteString+ prop_lazy_bytestring :: Bool prop_lazy_bytestring = $(lift $ ByteString.Lazy.pack bytedata) == ByteString.Lazy.pack bytedata++prop_big_lazy_bytestring :: Bool+prop_big_lazy_bytestring = $(lift bigLazyByteString) == bigLazyByteString  -------------------------------------------------------------------------------- -- Vector
th-lift-instances.cabal view
@@ -1,5 +1,5 @@ name: th-lift-instances-version: 0.1.11+version: 0.1.12 cabal-version: >=1.10 build-type: Simple license: BSD3@@ -30,17 +30,21 @@         Instances.TH.Lift     build-depends:         base >=4.3 && <5,-        template-haskell,-        th-lift,+        template-haskell >=2.5.0.0,         containers,         vector >= 0.4,         text,         bytestring     default-language: Haskell2010-    other-extensions: TemplateHaskell     hs-source-dirs: src     ghc-options: -Wall -fwarn-tabs +    if impl(ghc >= 8.0)+      other-extensions: TemplateHaskellQuotes+    else+      other-extensions: TemplateHaskell++ test-suite tests     type: exitcode-stdio-1.0     main-is: Main.hs@@ -53,6 +57,14 @@         bytestring,         th-lift-instances,         QuickCheck >=2.6+    if !impl(ghc >= 7.10)+      build-depends:+        nats >= 1.1.2 && < 1.2+    if !impl(ghc >= 8.0)+      build-depends:+        -- todo: we need to bump lower bound when new semigroups is released+        -- with NonEmpty instance+        semigroups          >= 0.18.5  && < 0.19     default-language: Haskell2010     other-extensions: TemplateHaskell     hs-source-dirs: tests