2
2
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3
3
{-# LANGUAGE PackageImports #-}
4
4
{-# LANGUAGE RankNTypes #-}
5
- {-# LANGUAGE TemplateHaskell #-}
5
+ {-# LANGUAGE TemplateHaskellQuotes #-}
6
6
{-# LANGUAGE DeriveGeneric #-}
7
7
{-# LANGUAGE TypeFamilies #-}
8
8
{-# LANGUAGE TypeApplications #-}
@@ -46,9 +46,7 @@ import GHC.Generics (Generic)
46
46
import System.OsString.Encoding.Internal
47
47
import qualified System.OsString.Data.ByteString.Short as BS
48
48
import qualified System.OsString.Data.ByteString.Short.Word16 as BS16
49
- #if MIN_VERSION_template_haskell(2,16,0)
50
49
import qualified Language.Haskell.TH.Syntax as TH
51
- #endif
52
50
53
51
-- Using unpinned bytearrays to avoid Heap fragmentation and
54
52
-- which are reasonably cheap to pass to FFI calls
@@ -77,8 +75,7 @@ pattern WS { unWS } <- WindowsString unWS where
77
75
78
76
79
77
instance Lift WindowsString where
80
- lift (WindowsString bs)
81
- = [| WindowsString (BS. pack $ (lift $ BS. unpack bs)) :: WindowsString | ]
78
+ lift (WindowsString bs) = TH. AppE (TH. ConE 'WindowsString) <$> (lift bs)
82
79
#if MIN_VERSION_template_haskell(2,17,0)
83
80
liftTyped = TH. unsafeCodeCoerce . TH. lift
84
81
#elif MIN_VERSION_template_haskell(2,16,0)
@@ -103,8 +100,7 @@ pattern PS { unPS } <- PosixString unPS where
103
100
#endif
104
101
105
102
instance Lift PosixString where
106
- lift (PosixString bs)
107
- = [| PosixString (BS. pack $ (lift $ BS. unpack bs)) :: PosixString | ]
103
+ lift (PosixString bs) = TH. AppE (TH. ConE 'PosixString) <$> (lift bs)
108
104
#if MIN_VERSION_template_haskell(2,17,0)
109
105
liftTyped = TH. unsafeCodeCoerce . TH. lift
110
106
#elif MIN_VERSION_template_haskell(2,16,0)
@@ -185,7 +181,7 @@ instance Monoid OsString where
185
181
#if MIN_VERSION_base(4,11,0)
186
182
mappend = (<>)
187
183
#else
188
- mappend = coerce (mappend :: BS. ShortByteString -> BS. ShortByteString -> BS. ShortByteString ))
184
+ mappend = coerce (mappend :: BS. ShortByteString -> BS. ShortByteString -> BS. ShortByteString )
189
185
#endif
190
186
191
187
#if MIN_VERSION_base(4,11,0)
@@ -197,9 +193,9 @@ instance Semigroup OsString where
197
193
instance Lift OsString where
198
194
lift xs = case coercionToPlatformTypes of
199
195
Left (_, co) ->
200
- [ | OsString ( WindowsString ( BS. pack $ (lift $ BS. unpack $ coerce $ coerceWith co xs))) :: OsString | ]
201
- Right (_, co) ->
202
- [ | OsString ( PosixString ( BS. pack $ (lift $ BS. unpack $ coerce $ coerceWith co xs))) :: OsString | ]
196
+ TH. AppE ( TH. ConE 'OsString) <$> (lift $ coerceWith co xs)
197
+ Right (_, co) -> do
198
+ TH. AppE ( TH. ConE 'OsString) <$> (lift $ coerceWith co xs)
203
199
#if MIN_VERSION_template_haskell(2,17,0)
204
200
liftTyped = TH. unsafeCodeCoerce . TH. lift
205
201
#elif MIN_VERSION_template_haskell(2,16,0)
0 commit comments