on master help sign in
Merge pull request #3 from obsidiansystems/explicit-instances

Change to explicit instances Show, Eq, Ord, IsString, Monoid, Read an…

commit34541bf635d21c0c81d8e62af7e50c528a119fd9 authorLuigy Leon <luichi.19@gmail.com> dateThu 20 Apr 2017, 20:30 (9 years ago) parent4d56c4d7bb8970
2 files changed+28−22
Data/Text.hs+24−19 Data/Text/Internal.hs+4−3
Data/Text.hs+24−19
@@ -373,12 +373,17 @@ unpackCString# addr# = Text $ SJS.unstream (SJS.streamCString# addr#)
373373-- | lenA == lenB = A.equal arrA offA arrB offB lenA
374374-- | otherwise = False
375375-- {-# INLINE (==) #-}
376+instance Eq Text where
377+ Text x == Text y = x == y
376378
377379-- instance Ord Text where
378380-- compare = compareText
379381
380−-- instance Read Text where
381−-- readsPrec p str = [(pack x,y) | (x,y) <- readsPrec p str]
382+instance Ord Text where
383+ compare (Text x) (Text y) = compare x y
384+
385+instance Read Text where
386+ readsPrec p str = [(pack x,y) | (x,y) <- readsPrec p str]
382387
383388#if MIN_VERSION_base(4,9,0)
384389-- Semigroup orphan instances for older GHCs are provided by
@@ -388,17 +393,17 @@ instance Semigroup Text where
388393 (<>) = append
389394#endif
390395
391−-- instance Monoid Text where
392−-- mempty = empty
393−-- #if MIN_VERSION_base(4,9,0)
394−-- mappend = (<>) -- future-proof definition
395−-- #else
396−-- mappend = append
397−-- #endif
398−-- mconcat = concat
396+instance Monoid Text where
397+ mempty = empty
398+#if MIN_VERSION_base(4,9,0)
399+ mappend = (<>) -- future-proof definition
400+#else
401+ mappend = append
402+#endif
403+ mconcat = concat
399404
400−-- instance IsString Text where
401−-- fromString = pack
405+instance IsString Text where
406+ fromString = pack
402407
403408#if __GLASGOW_HASKELL__ >= 708
404409instance Exts.IsList Text where
@@ -434,13 +439,13 @@ instance Binary Text where
434439-- and 'Data.Map.Map' is archived here:
435440-- <http://markmail.org/message/trovdc6zkphyi3cr#query:+page:1+mid:a46der3iacwjcf6n+state:results Proposal: Allow gunfold for Data.Map, ... >
436441
437−-- instance Data Text where
438−-- gfoldl f z txt = z pack `f` (unpack txt)
439−-- toConstr _ = packConstr
440−-- gunfold k z c = case constrIndex c of
441−-- 1 -> k (z pack)
442−-- _ -> P.error "gunfold"
443−-- dataTypeOf _ = textDataType
442+instance Data Text where
443+ gfoldl f z txt = z pack `f` (unpack txt)
444+ toConstr _ = packConstr
445+ gunfold k z c = case constrIndex c of
446+ 1 -> k (z pack)
447+ _ -> P.error "gunfold"
448+ dataTypeOf _ = textDataType
444449
445450#if MIN_VERSION_base(4,7,0)
446451-- | Only defined for @base-4.7.0.0@ and later
Data/Text/Internal.hs+4−3
@@ -34,9 +34,10 @@ import qualified GHC.CString as GHC
3434
3535
3636newtype Text = Text JSString
37− deriving ( Show, Eq, Ord, IsString, Monoid, Read, Data
38− , PToJSVal, PFromJSVal, FromJSVal, ToJSVal
39− )
37+ deriving (PToJSVal, PFromJSVal, FromJSVal, ToJSVal)
38+
39+instance Show Text where
40+ showsPrec p (Text jsstring) r = showsPrec p jsstring r
4041
4142empty :: Text
4243empty = Text JSS.empty