Skip to content

Commit 9c71692

Browse files
committed
Merge remote-tracking branch 'github/pr/21'
2 parents 4390b95 + 6a175fa commit 9c71692

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

System/OsString/Internal/Types.hs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
33
{-# LANGUAGE PackageImports #-}
44
{-# LANGUAGE RankNTypes #-}
5-
{-# LANGUAGE TemplateHaskell #-}
5+
{-# LANGUAGE TemplateHaskellQuotes #-}
66
{-# LANGUAGE DeriveGeneric #-}
77
{-# LANGUAGE TypeFamilies #-}
88
{-# LANGUAGE TypeApplications #-}
@@ -46,9 +46,7 @@ import GHC.Generics (Generic)
4646
import System.OsString.Encoding.Internal
4747
import qualified System.OsString.Data.ByteString.Short as BS
4848
import qualified System.OsString.Data.ByteString.Short.Word16 as BS16
49-
#if MIN_VERSION_template_haskell(2,16,0)
5049
import qualified Language.Haskell.TH.Syntax as TH
51-
#endif
5250

5351
-- Using unpinned bytearrays to avoid Heap fragmentation and
5452
-- which are reasonably cheap to pass to FFI calls
@@ -77,8 +75,7 @@ pattern WS { unWS } <- WindowsString unWS where
7775

7876

7977
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)
8279
#if MIN_VERSION_template_haskell(2,17,0)
8380
liftTyped = TH.unsafeCodeCoerce . TH.lift
8481
#elif MIN_VERSION_template_haskell(2,16,0)
@@ -103,8 +100,7 @@ pattern PS { unPS } <- PosixString unPS where
103100
#endif
104101

105102
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)
108104
#if MIN_VERSION_template_haskell(2,17,0)
109105
liftTyped = TH.unsafeCodeCoerce . TH.lift
110106
#elif MIN_VERSION_template_haskell(2,16,0)
@@ -185,7 +181,7 @@ instance Monoid OsString where
185181
#if MIN_VERSION_base(4,11,0)
186182
mappend = (<>)
187183
#else
188-
mappend = coerce (mappend :: BS.ShortByteString -> BS.ShortByteString -> BS.ShortByteString))
184+
mappend = coerce (mappend :: BS.ShortByteString -> BS.ShortByteString -> BS.ShortByteString)
189185
#endif
190186

191187
#if MIN_VERSION_base(4,11,0)
@@ -197,9 +193,9 @@ instance Semigroup OsString where
197193
instance Lift OsString where
198194
lift xs = case coercionToPlatformTypes of
199195
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)
203199
#if MIN_VERSION_template_haskell(2,17,0)
204200
liftTyped = TH.unsafeCodeCoerce . TH.lift
205201
#elif MIN_VERSION_template_haskell(2,16,0)

0 commit comments

Comments
 (0)