    {-# LANGUAGE TypeFamilies, FlexibleInstances #-}
    module Data.Interned.Internal.Text
      ( InternedText(..)
      ) where

    import Data.String
    import Data.Interned
    import Data.Text
    import Data.Hashable

    data InternedText = InternedText
      { InternedText -> Id
    internedTextId :: {-# UNPACK #-} !Id
      , InternedText -> Text
    uninternedText :: {-# UNPACK #-} !Text
      }

    instance IsString InternedText where
      fromString :: String -> InternedText
    fromString = Text -> InternedText
    forall t. Interned t => Uninterned t -> t
    intern (Text -> InternedText)
    -> (String -> Text) -> String -> InternedText
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> Text
    pack

    instance Eq InternedText where
      InternedText i :: Id
    i _ == :: InternedText -> InternedText -> Bool
    == InternedText j :: Id
    j _ = Id
    i Id -> Id -> Bool
    forall a. Eq a => a -> a -> Bool
    == Id
    j

    instance Ord InternedText where
      compare :: InternedText -> InternedText -> Ordering
    compare (InternedText i :: Id
    i _) (InternedText j :: Id
    j _) = Id -> Id -> Ordering
    forall a. Ord a => a -> a -> Ordering
    compare Id
    i Id
    j

    instance Show InternedText where
      showsPrec :: Id -> InternedText -> ShowS
    showsPrec d :: Id
    d (InternedText _ b :: Text
    b) = Id -> Text -> ShowS
    forall a. Show a => Id -> a -> ShowS
    showsPrec Id
    d Text
    b

    instance Hashable InternedText where
      hashWithSalt :: Id -> InternedText -> Id
    hashWithSalt s :: Id
    s (InternedText i :: Id
    i _) = Id -> Id -> Id
    forall a. Hashable a => Id -> a -> Id
    hashWithSalt Id
    s Id
    i

    instance Interned InternedText where
      type Uninterned InternedText = Text
      newtype Description InternedText = DT Text deriving (Description InternedText -> Description InternedText -> Bool
    (Description InternedText -> Description InternedText -> Bool)
    -> (Description InternedText -> Description InternedText -> Bool)
    -> Eq (Description InternedText)
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: Description InternedText -> Description InternedText -> Bool
    $c/= :: Description InternedText -> Description InternedText -> Bool
    == :: Description InternedText -> Description InternedText -> Bool
    $c== :: Description InternedText -> Description InternedText -> Bool
    Eq)
      describe :: Uninterned InternedText -> Description InternedText
    describe = Text -> Description InternedText
    Uninterned InternedText -> Description InternedText
    DT
      identify :: Id -> Uninterned InternedText -> InternedText
    identify = Id -> Text -> InternedText
    Id -> Uninterned InternedText -> InternedText
    InternedText
      cache :: Cache InternedText
    cache = Cache InternedText
    itCache

    instance Uninternable InternedText where
      unintern :: InternedText -> Uninterned InternedText
    unintern (InternedText _ b :: Text
    b) = Text
    Uninterned InternedText
    b

    instance Hashable (Description InternedText) where
      hashWithSalt :: Id -> Description InternedText -> Id
    hashWithSalt s :: Id
    s (DT h) = Id -> Text -> Id
    forall a. Hashable a => Id -> a -> Id
    hashWithSalt Id
    s Text
    h

    itCache :: Cache InternedText
    itCache :: Cache InternedText
    itCache = Cache InternedText
    forall t. Interned t => Cache t
    mkCache
    {-# NOINLINE itCache #-}