th-lift-instances 0.1.15 → 0.1.16
raw patch · 2 files changed
+54/−40 lines, 2 files
Files
- src/Instances/TH/Lift.hs +53/−39
- th-lift-instances.cabal +1/−1
src/Instances/TH/Lift.hs view
@@ -113,15 +113,10 @@ import Control.Applicative (Const (..)) import Data.Functor.Identity (Identity (..)) --- support typed template haskell (requires template-haskell>=1.16) #if MIN_VERSION_template_haskell(2,16,0)-#define LIFT liftTyped-#define QUOTE(x) [|| (x) ||]-#define TYPED_RETURN unsafeTExpCoerce . return+#define LIFT_TYPED_DEFAULT liftTyped = unsafeTExpCoerce . lift #else-#define LIFT lift-#define QUOTE(x) [| (x) |]-#define TYPED_RETURN return+#define LIFT_TYPED_DEFAULT #endif --------------------------------------------------------------------------------@@ -193,45 +188,53 @@ -------------------------------------------------------------------------------- -- Containers instance Lift v => Lift (IntMap.IntMap v) where- LIFT m = QUOTE(IntMap.fromDistinctAscList ml) where- ml = IntMap.toAscList m+ lift m = [| IntMap.fromList m' |] where+ m' = IntMap.toList m+ LIFT_TYPED_DEFAULT instance Lift IntSet.IntSet where- LIFT s = QUOTE(IntSet.fromDistinctAscList sl) where- sl = IntSet.toAscList s+ lift s = [| IntSet.fromList s' |] where+ s' = IntSet.toList s+ LIFT_TYPED_DEFAULT instance (Lift k, Lift v) => Lift (Map.Map k v) where- LIFT m = QUOTE(Map.fromDistinctAscList ml) where- ml = Map.toAscList m+ lift m = [| Map.fromList m' |] where+ m' = Map.toList m+ LIFT_TYPED_DEFAULT instance Lift a => Lift (Sequence.Seq a) where- LIFT s = QUOTE(Sequence.fromList sl) where- sl = F.toList s+ lift s = [| Sequence.fromList s' |] where+ s' = F.toList s+ LIFT_TYPED_DEFAULT instance Lift a => Lift (Set.Set a) where- LIFT s = QUOTE(Set.fromDistinctAscList sl) where- sl = Set.toAscList s+ lift s = [| Set.fromList s' |] where+ s' = Set.toList s+ LIFT_TYPED_DEFAULT instance Lift a => Lift (Tree.Tree a) where- LIFT (Tree.Node x xs) = QUOTE(Tree.Node x xs)+ lift (Tree.Node x xs) = [| Tree.Node x xs |]+ LIFT_TYPED_DEFAULT #if !MIN_VERSION_text(1,2,4) -------------------------------------------------------------------------------- -- Text instance Lift Text.Text where- LIFT t = QUOTE(Text.pack tp) where- tp = Text.unpack t+ lift t = [| Text.pack t' |] where+ t' = Text.unpack t+ LIFT_TYPED_DEFAULT instance Lift Text.Lazy.Text where- LIFT t = QUOTE(Text.Lazy.pack tp) where- tp = Text.Lazy.unpack t+ lift t = [| Text.Lazy.pack t' |] where+ t' = Text.Lazy.unpack t+ LIFT_TYPED_DEFAULT #endif -------------------------------------------------------------------------------- -- ByteString instance Lift ByteString.ByteString where -- this is essentially what e.g. file-embed does- LIFT b = TYPED_RETURN $ AppE (VarE 'unsafePerformIO) $+ lift b = return $ AppE (VarE 'unsafePerformIO) $ VarE 'ByteString.Unsafe.unsafePackAddressLen `AppE` l `AppE` b' where l = LitE $ IntegerL $ fromIntegral $ ByteString.length b@@ -241,37 +244,48 @@ #else LitE $ StringPrimL $ ByteString.Char8.unpack b #endif+ LIFT_TYPED_DEFAULT instance Lift ByteString.Lazy.ByteString where- LIFT lb = QUOTE(ByteString.Lazy.fromChunks bc) where- bc = ByteString.Lazy.toChunks lb+ lift lb = do+ b' <- lift b+ return (VarE 'ByteString.Lazy.fromChunks `AppE` b')+ where+ b = ByteString.Lazy.toChunks lb+ LIFT_TYPED_DEFAULT -------------------------------------------------------------------------------- -- Vector instance (Vector.Primitive.Prim a, Lift a) => Lift (Vector.Primitive.Vector a) where- LIFT v = QUOTE(Vector.Primitive.fromListN np vp) where- np = Vector.Primitive.length v- vp = Vector.Primitive.toList v+ lift v = [| Vector.Primitive.fromListN n' v' |] where+ n' = Vector.Primitive.length v+ v' = Vector.Primitive.toList v+ LIFT_TYPED_DEFAULT instance (Vector.Storable.Storable a, Lift a) => Lift (Vector.Storable.Vector a) where- LIFT v = QUOTE(Vector.Storable.fromListN np vp) where- np = Vector.Storable.length v- vp = Vector.Storable.toList v+ lift v = [| Vector.Storable.fromListN n' v' |] where+ n' = Vector.Storable.length v+ v' = Vector.Storable.toList v+ LIFT_TYPED_DEFAULT instance (Vector.Unboxed.Unbox a, Lift a) => Lift (Vector.Unboxed.Vector a) where- LIFT v = QUOTE(Vector.Unboxed.fromListN np vp) where- np = Vector.Unboxed.length v- vp = Vector.Unboxed.toList v+ lift v = [| Vector.Unboxed.fromListN n' v' |] where+ n' = Vector.Unboxed.length v+ v' = Vector.Unboxed.toList v+ LIFT_TYPED_DEFAULT instance Lift a => Lift (Vector.Boxed.Vector a) where- LIFT v = QUOTE(Vector.Boxed.fromListN np vp) where- np = Vector.Boxed.length v- vp = Vector.Boxed.toList v+ lift v = [| Vector.Boxed.fromListN n' v' |] where+ n' = Vector.Boxed.length v+ v' = Vector.Boxed.toList v+ LIFT_TYPED_DEFAULT -------------------------------------------------------------------------------- -- Transformers instance Lift a => Lift (Identity a) where- LIFT (Identity a) = QUOTE(Identity a)+ lift (Identity a) = [| Identity a |]+ LIFT_TYPED_DEFAULT instance Lift a => Lift (Const a b) where- LIFT (Const a) = QUOTE(Const a)+ lift (Const a) = [| Const a |]+ LIFT_TYPED_DEFAULT
th-lift-instances.cabal view
@@ -1,5 +1,5 @@ name: th-lift-instances-version: 0.1.15+version: 0.1.16 cabal-version: >=1.10 build-type: Simple license: BSD3