{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
module Retrie.Quantifiers
( Quantifiers
, emptyQs
, exceptQ
, isQ
, mkQs
, mkFSQs
, qList
, qSet
, unionQ
) where
import GHC.Exts (IsList(..))
import Retrie.GHC
instance IsList Quantifiers where
type Item Quantifiers = String
fromList :: [Item Quantifiers] -> Quantifiers
fromList = [FastString] -> Quantifiers
mkFSQs ([FastString] -> Quantifiers)
-> ([String] -> [FastString]) -> [String] -> Quantifiers
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> FastString) -> [String] -> [FastString]
forall a b. (a -> b) -> [a] -> [b]
map String -> FastString
mkFastString
toList :: Quantifiers -> [Item Quantifiers]
toList = (FastString -> String) -> [FastString] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map FastString -> String
unpackFS ([FastString] -> [String])
-> (Quantifiers -> [FastString]) -> Quantifiers -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Quantifiers -> [FastString]
qList
newtype Quantifiers = Quantifiers
{ Quantifiers -> UniqSet FastString
qSet :: UniqSet FastString
}
instance Show Quantifiers where
show :: Quantifiers -> String
show Quantifiers
qs = String
"Quantifiers " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [FastString] -> String
forall a. Show a => a -> String
show (Quantifiers -> [FastString]
qList Quantifiers
qs)
mkQs :: [RdrName] -> Quantifiers
mkQs :: [RdrName] -> Quantifiers
mkQs = [FastString] -> Quantifiers
mkFSQs ([FastString] -> Quantifiers)
-> ([RdrName] -> [FastString]) -> [RdrName] -> Quantifiers
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RdrName -> FastString) -> [RdrName] -> [FastString]
forall a b. (a -> b) -> [a] -> [b]
map RdrName -> FastString
rdrFS
mkFSQs :: [FastString] -> Quantifiers
mkFSQs :: [FastString] -> Quantifiers
mkFSQs = UniqSet FastString -> Quantifiers
Quantifiers (UniqSet FastString -> Quantifiers)
-> ([FastString] -> UniqSet FastString)
-> [FastString]
-> Quantifiers
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [FastString] -> UniqSet FastString
forall a. Uniquable a => [a] -> UniqSet a
mkUniqSet
emptyQs :: Quantifiers
emptyQs :: Quantifiers
emptyQs = UniqSet FastString -> Quantifiers
Quantifiers UniqSet FastString
forall a. UniqSet a
emptyUniqSet
isQ :: RdrName -> Quantifiers -> Bool
isQ :: RdrName -> Quantifiers -> Bool
isQ RdrName
r (Quantifiers UniqSet FastString
s) = FastString -> UniqSet FastString -> Bool
forall a. Uniquable a => a -> UniqSet a -> Bool
elementOfUniqSet (RdrName -> FastString
rdrFS RdrName
r) UniqSet FastString
s
unionQ :: Quantifiers -> Quantifiers -> Quantifiers
unionQ :: Quantifiers -> Quantifiers -> Quantifiers
unionQ (Quantifiers UniqSet FastString
s) (Quantifiers UniqSet FastString
t) = UniqSet FastString -> Quantifiers
Quantifiers (UniqSet FastString -> Quantifiers)
-> UniqSet FastString -> Quantifiers
forall a b. (a -> b) -> a -> b
$ UniqSet FastString -> UniqSet FastString -> UniqSet FastString
forall a. UniqSet a -> UniqSet a -> UniqSet a
unionUniqSets UniqSet FastString
s UniqSet FastString
t
exceptQ :: Quantifiers -> [RdrName] -> Quantifiers
exceptQ :: Quantifiers -> [RdrName] -> Quantifiers
exceptQ (Quantifiers UniqSet FastString
s) [RdrName]
rs =
UniqSet FastString -> Quantifiers
Quantifiers (UniqSet FastString -> Quantifiers)
-> UniqSet FastString -> Quantifiers
forall a b. (a -> b) -> a -> b
$ UniqSet FastString -> [FastString] -> UniqSet FastString
forall a. Uniquable a => UniqSet a -> [a] -> UniqSet a
delListFromUniqSet UniqSet FastString
s ((RdrName -> FastString) -> [RdrName] -> [FastString]
forall a b. (a -> b) -> [a] -> [b]
map RdrName -> FastString
rdrFS [RdrName]
rs)
qList :: Quantifiers -> [FastString]
qList :: Quantifiers -> [FastString]
qList (Quantifiers UniqSet FastString
s) = UniqSet FastString -> [FastString]
forall elt. UniqSet elt -> [elt]
nonDetEltsUniqSet UniqSet FastString
s