th-lift-instances-0.1.11/0000755000000000000000000000000013021057463013315 5ustar0000000000000000th-lift-instances-0.1.11/LICENSE0000644000000000000000000000266513021057463014333 0ustar0000000000000000Copyright 2013-2016 Benno Fünfstück All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the author nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. th-lift-instances-0.1.11/Setup.hs0000644000000000000000000000005613021057463014752 0ustar0000000000000000import Distribution.Simple main = defaultMain th-lift-instances-0.1.11/th-lift-instances.cabal0000644000000000000000000000305413021057463017637 0ustar0000000000000000name: th-lift-instances version: 0.1.11 cabal-version: >=1.10 build-type: Simple license: BSD3 license-file: LICENSE copyright: Copyright (C) 2013-2016 Benno Fünfstück maintainer: Benno Fünfstück stability: experimental homepage: http://github.com/bennofs/th-lift-instances/ bug-reports: http://github.com/bennofs/th-lift-instances/issues synopsis: Lift instances for template-haskell for common data types. description: Most data types in haskell platform do not have Lift instances. This package provides orphan instances for containers, text, bytestring and vector. category: Template Haskell author: Benno Fünfstück extra-source-files: .ghci .gitignore .travis.yml README.md source-repository head type: git location: https://github.com/bennofs/th-lift-instances.git library exposed-modules: Instances.TH.Lift build-depends: base >=4.3 && <5, template-haskell, th-lift, containers, vector >= 0.4, text, bytestring default-language: Haskell2010 other-extensions: TemplateHaskell hs-source-dirs: src ghc-options: -Wall -fwarn-tabs test-suite tests type: exitcode-stdio-1.0 main-is: Main.hs build-depends: base <5, template-haskell, containers, vector >= 0.4, text, bytestring, th-lift-instances, QuickCheck >=2.6 default-language: Haskell2010 other-extensions: TemplateHaskell hs-source-dirs: tests other-modules: Data th-lift-instances-0.1.11/.ghci0000644000000000000000000000012513021057463014226 0ustar0000000000000000:set -isrc -idist/build/autogen -optP-include -optPdist/build/autogen/cabal_macros.h th-lift-instances-0.1.11/.gitignore0000644000000000000000000000016313021057463015305 0ustar0000000000000000dist docs wiki TAGS tags wip .DS_Store .*.swp .*.swo *.o *.hi *~ *# .cabal-sandbox cabal.sandbox.config .stack-workth-lift-instances-0.1.11/.travis.yml0000644000000000000000000000357613021057463015441 0ustar0000000000000000language: c sudo: false cache: directories: - $HOME/.cabsnap - $HOME/.cabal/packages - $HOME/tools before_cache: - rm -f $HOME/.cabal/packages/hackage.haskell.org/build-reports.log - rm -f $HOME/.cabal/packages/hackage.haskell.org/00-index.tar before_install: source travis/setup.sh install: travis/install.sh 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" addons: {apt: {packages: [cabal-install-1.24, ghc-8.0.1, 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]}} allow_failures: - compiler: ": #GHC head" fast_finish: true th-lift-instances-0.1.11/README.md0000644000000000000000000000035613021057463014600 0ustar0000000000000000th-lift-instances ==================== [![Build Status](https://secure.travis-ci.org/bennofs/th-lift-instances.png?branch=master)](http://travis-ci.org/bennofs/th-lift-instances) Some more Lift instances for common haskell data types. th-lift-instances-0.1.11/src/0000755000000000000000000000000013021057463014104 5ustar0000000000000000th-lift-instances-0.1.11/src/Instances/0000755000000000000000000000000013021057463016033 5ustar0000000000000000th-lift-instances-0.1.11/src/Instances/TH/0000755000000000000000000000000013021057463016346 5ustar0000000000000000th-lift-instances-0.1.11/src/Instances/TH/Lift.hs0000644000000000000000000001243413021057463017604 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-orphans #-} {-# LANGUAGE TemplateHaskell, CPP #-} 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. -- -- Lift instances are useful to precompute values at compile time using template haskell. For example, if you write the following code, -- you can make sure that @3 * 10@ is really computed at compile time: -- -- > {-# LANGUAGE TemplateHaskell #-} -- > -- > import Language.Haskell.TH.Syntax -- > -- > expensiveComputation :: Word32 -- > expensiveComputation = $(lift $ 3 * 10) -- This will computed at compile time -- -- This uses the Lift instance for Word32. -- -- The following instances are provided by this package: -- * Base -- | * 'Word8', 'Word16', 'Word32', 'Word64' -- -- * 'Int8', 'Int16', 'Int32', 'Int64' -- * Containers (both strict/lazy) -- | * 'Data.IntMap.IntMap' -- -- * 'Data.IntSet.IntSet' -- -- * 'Data.Map.Map' -- -- * 'Data.Set.Set' -- -- * 'Data.Tree.Tree' -- -- * 'Data.Sequence.Seq' -- * ByteString (both strict/lazy) -- | * 'Data.ByteString.ByteString' -- * Text (both strict/lazy) -- | * 'Data.Text.Text' -- * Vector (Boxed, Unboxed, Storable, Primitive) -- | * 'Data.Vector.Vector' ) where import Language.Haskell.TH.Lift (deriveLift) import Language.Haskell.TH.Syntax (Lift(..)) 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 -- Containers import qualified Data.IntMap as IntMap import qualified Data.IntSet as IntSet import qualified Data.Map as Map import qualified Data.Sequence as Sequence import qualified Data.Set as Set import qualified Data.Tree as Tree -- Text import qualified Data.Text as Text import qualified Data.Text.Lazy as Text.Lazy -- ByteString import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as ByteString.Lazy -- 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 -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- #if !MIN_VERSION_template_haskell(2,9,1) -- Base instance Lift Word8 where lift x = [| fromInteger $(lift $ toInteger x) :: Word8 |] instance Lift Word16 where lift x = [| fromInteger $(lift $ toInteger x) :: Word16 |] instance Lift Word32 where lift x = [| fromInteger $(lift $ toInteger x) :: Word32 |] instance Lift Word64 where lift x = [| fromInteger $(lift $ toInteger x) :: Word64 |] instance Lift Int8 where lift x = [| fromInteger $(lift $ toInteger x) :: Int8 |] instance Lift Int16 where lift x = [| fromInteger $(lift $ toInteger x) :: Int16 |] instance Lift Int32 where lift x = [| fromInteger $(lift $ toInteger x) :: Int32 |] instance Lift Int64 where lift x = [| fromInteger $(lift $ toInteger x) :: Int64 |] instance Lift Float where lift x = [| $(litE $ rationalL $ toRational x) :: Float |] instance Lift Double where lift x = [| $(litE $ rationalL $ toRational x) :: Double |] # endif -------------------------------------------------------------------------------- -- Containers instance Lift v => Lift (IntMap.IntMap v) where lift m = [| IntMap.fromList $(lift $ IntMap.toList m) |] instance Lift IntSet.IntSet where lift s = [| IntSet.fromList $(lift $ IntSet.toList s) |] instance (Lift k, Lift v) => Lift (Map.Map k v) where lift m = [| Map.fromList $(lift $ Map.toList m) |] instance Lift a => Lift (Sequence.Seq a) where lift s = [| Sequence.fromList $(lift $ F.toList s) |] instance Lift a => Lift (Set.Set a) where lift s = [| Set.fromList $(lift $ Set.toList s) |] deriveLift ''Tree.Tree -------------------------------------------------------------------------------- -- Text instance Lift Text.Text where lift t = [| Text.pack $(lift $ Text.unpack t) |] instance Lift Text.Lazy.Text where lift t = [| Text.Lazy.pack $(lift $ Text.Lazy.unpack t) |] -------------------------------------------------------------------------------- -- ByteString instance Lift ByteString.ByteString where lift b = [| ByteString.pack $(lift $ ByteString.unpack b) |] instance Lift ByteString.Lazy.ByteString where lift b = [| ByteString.Lazy.pack $(lift $ ByteString.Lazy.unpack b) |] -------------------------------------------------------------------------------- -- Vector instance (Vector.Primitive.Prim a, Lift a) => Lift (Vector.Primitive.Vector a) where lift v = [| Vector.Primitive.fromList $(lift $ 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) |] instance (Vector.Unboxed.Unbox a, Lift a) => Lift (Vector.Unboxed.Vector a) where lift v = [| Vector.Unboxed.fromList $(lift $ Vector.Unboxed.toList v) |] instance Lift a => Lift (Vector.Boxed.Vector a) where lift v = [| Vector.Boxed.fromList $(lift $ Vector.Boxed.toList v) |] th-lift-instances-0.1.11/tests/0000755000000000000000000000000013021057463014457 5ustar0000000000000000th-lift-instances-0.1.11/tests/Main.hs0000644000000000000000000000701013021057463015675 0ustar0000000000000000{-# LANGUAGE TemplateHaskell #-} module Main where import Data import Control.Monad import Data.Int import Data.Word import Instances.TH.Lift() import Language.Haskell.TH.Syntax import System.Exit import Test.QuickCheck.All import qualified Data.IntMap as IntMap import qualified Data.IntSet as IntSet import qualified Data.Map as Map import qualified Data.Sequence as Sequence import qualified Data.Set as Set import qualified Data.Text as Text import qualified Data.Text.Lazy as Text.Lazy import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as ByteString.Lazy 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 -------------------------------------------------------------------------------- -- Base prop_word8 :: Bool prop_word8 = $(lift (10 :: Word8)) == (10 :: Word8) prop_word16 :: Bool prop_word16 = $(lift (10 :: Word16)) == (10 :: Word16) prop_word32 :: Bool prop_word32 = $(lift (10 :: Word32)) == (10 :: Word32) prop_word64 :: Bool prop_word64 = $(lift (10 :: Word64)) == (10 :: Word64) prop_int8 :: Bool prop_int8 = $(lift (10 :: Int8)) == (10 :: Int8) prop_int16 :: Bool prop_int16 = $(lift (10 :: Int16)) == (10 :: Int16) prop_int32 :: Bool prop_int32 = $(lift (10 :: Int32)) == (10 :: Int32) prop_int64 :: Bool prop_int64 = $(lift (10 :: Int64)) == (10 :: Int64) prop_float :: Bool prop_float = $(lift (1.1 :: Float)) == (1.1 :: Float) prop_double :: Bool prop_double = $(lift (1.1 :: Double)) == (1.1 :: Double) -------------------------------------------------------------------------------- -- Containers prop_lazy_int_map :: Bool prop_lazy_int_map = $(lift $ IntMap.fromList mapdata) == IntMap.fromList mapdata prop_lazy_map :: Bool prop_lazy_map = $(lift $ Map.fromList mapdata) == Map.fromList mapdata prop_int_set :: Bool prop_int_set = $(lift $ IntSet.fromList setdata) == IntSet.fromList setdata prop_set :: Bool prop_set = $(lift $ Set.fromList setdata) == Set.fromList setdata prop_tree :: Bool prop_tree = $(lift treedata) == treedata prop_sequence :: Bool prop_sequence = $(lift $ Sequence.fromList setdata) == Sequence.fromList setdata -------------------------------------------------------------------------------- -- Text prop_text :: Bool prop_text = $(lift $ Text.pack textdata) == Text.pack textdata prop_lazy_text :: Bool prop_lazy_text = $(lift $ Text.Lazy.pack textdata) == Text.Lazy.pack textdata -------------------------------------------------------------------------------- -- ByteString prop_bytestring :: Bool prop_bytestring = $(lift $ ByteString.pack bytedata) == ByteString.pack bytedata prop_lazy_bytestring :: Bool prop_lazy_bytestring = $(lift $ ByteString.Lazy.pack bytedata) == ByteString.Lazy.pack bytedata -------------------------------------------------------------------------------- -- Vector prop_boxed_vector :: Bool prop_boxed_vector = $(lift $ Vector.Boxed.fromList bytedata) == Vector.Boxed.fromList bytedata prop_unboxed_vector :: Bool prop_unboxed_vector = $(lift $ Vector.Unboxed.fromList bytedata) == Vector.Unboxed.fromList bytedata prop_primitive_vector :: Bool prop_primitive_vector = $(lift $ Vector.Primitive.fromList bytedata) == Vector.Primitive.fromList bytedata prop_storable_vector :: Bool prop_storable_vector = $(lift $ Vector.Storable.fromList bytedata) == Vector.Storable.fromList bytedata return [] main :: IO () main = do success <- $quickCheckAll unless success exitFailure th-lift-instances-0.1.11/tests/Data.hs0000644000000000000000000000062013021057463015662 0ustar0000000000000000module Data where import Data.Tree import Data.Word mapdata :: [(Int, Int)] mapdata = [(10, 20), (3,13), (2242,234), (324, 543)] 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 []]] textdata :: String textdata = "Some text! Hello world!" bytedata :: [Word8] bytedata = map fromIntegral setdata