1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
{-# LANGUAGE TypeFamilies, FlexibleInstances #-}
module Data.Interned.Internal.Text
( InternedText(..)
) where
import Data.String
import Data.Interned
import qualified Data.Text as T
import Data.Text (Text)
import Data.Hashable
data InternedText = InternedText
{ internedTextId :: {-# UNPACK #-} !Id
, uninternedText :: {-# UNPACK #-} !Text
}
instance IsString InternedText where
fromString = intern . T.pack
instance Eq InternedText where
InternedText i _ == InternedText j _ = i == j
instance Ord InternedText where
compare (InternedText i _) (InternedText j _) = compare i j
instance Show InternedText where
showsPrec d (InternedText _ b) = showsPrec d b
instance Hashable InternedText where
hashWithSalt s (InternedText i _) = hashWithSalt s i
instance Interned InternedText where
type Uninterned InternedText = Text
newtype Description InternedText = DT Text deriving (Eq)
describe = DT
identify = InternedText
cache = itCache
instance Uninternable InternedText where
unintern (InternedText _ b) = b
instance Hashable (Description InternedText) where
hashWithSalt s (DT h) = hashWithSalt s h
itCache :: Cache InternedText
itCache = mkCache
{-# NOINLINE itCache #-}
|