{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
#if (__GLASGOW_HASKELL__ >= 802)
{-# LANGUAGE DerivingStrategies #-}
#endif
module Data.Interned.URI
( InternedURI
) where
import Data.String (IsString(..))
import Data.Hashable
import Data.Interned
import Data.Maybe (fromMaybe)
import Network.URI
data InternedURI = InternedURI !Int !URI
instance IsString InternedURI where
fromString :: String -> InternedURI
fromString = forall t. Interned t => Uninterned t -> t
intern forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a. a -> Maybe a -> a
fromMaybe (forall a. HasCallStack => String -> a
error String
"Error: unable to create a URI.") forall b c a. (b -> c) -> (a -> b) -> a -> c
.
String -> Maybe URI
parseURIReference
instance Eq InternedURI where
InternedURI Int
a URI
_ == :: InternedURI -> InternedURI -> Bool
== InternedURI Int
b URI
_ = Int
a forall a. Eq a => a -> a -> Bool
== Int
b
instance Ord InternedURI where
compare :: InternedURI -> InternedURI -> Ordering
compare (InternedURI Int
a URI
_) (InternedURI Int
b URI
_) = forall a. Ord a => a -> a -> Ordering
compare Int
a Int
b
instance Show InternedURI where
showsPrec :: Int -> InternedURI -> ShowS
showsPrec Int
d (InternedURI Int
_ URI
b) = forall a. Show a => Int -> a -> ShowS
showsPrec Int
d URI
b
instance Interned InternedURI where
type Uninterned InternedURI = URI
data Description InternedURI = DU !URI
deriving
#if (__GLASGOW_HASKELL__ >= 802)
stock
#endif
(Description InternedURI -> Description InternedURI -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Description InternedURI -> Description InternedURI -> Bool
$c/= :: Description InternedURI -> Description InternedURI -> Bool
== :: Description InternedURI -> Description InternedURI -> Bool
$c== :: Description InternedURI -> Description InternedURI -> Bool
Eq)
describe :: Uninterned InternedURI -> Description InternedURI
describe = URI -> Description InternedURI
DU
identify :: Int -> Uninterned InternedURI -> InternedURI
identify = Int -> URI -> InternedURI
InternedURI
#if MIN_VERSION_intern(0,9,0)
#else
identity (InternedURI i _) = i
#endif
cache :: Cache InternedURI
cache = Cache InternedURI
iuCache
instance Uninternable InternedURI where
unintern :: InternedURI -> Uninterned InternedURI
unintern (InternedURI Int
_ URI
b) = URI
b
instance Hashable (Description InternedURI) where
#if MIN_VERSION_hashable(1,2,0)
#else
hash = hashWithSalt 5381
#endif
hashWithSalt :: Int -> Description InternedURI -> Int
hashWithSalt Int
salt (DU URI
u) = forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt ((forall a. [a] -> [a]
reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show) URI
u)
iuCache :: Cache InternedURI
iuCache :: Cache InternedURI
iuCache = forall t. Interned t => Cache t
mkCache
{-# NOINLINE iuCache #-}