GHC.Core.RoughMap

ghc-lib-parser-9.14.1.20251220: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Core.RoughMap

Contents

- RoughMatchTc
- RoughMap

Description

`RoughMap` is an approximate finite map data structure keyed on `[`RoughMatchTc`]`. This is useful when keying maps on lists of `Type`s (e.g. an instance head).

Synopsis

- data RoughMatchTc
  - = RM_KnownTc Name
  - | RM_WildCard
- isRoughWildcard :: RoughMatchTc -> Bool
- typeToRoughMatchTc :: Type -> RoughMatchTc
- data RoughMatchLookupTc
  - = RML_KnownTc Name
  - | RML_NoKnownTc
  - | RML_WildCard
- typeToRoughMatchLookupTc :: Type -> RoughMatchLookupTc
- roughMatchTcToLookup :: RoughMatchTc -> RoughMatchLookupTc
- roughMatchTcs :: [Type] -> [RoughMatchTc]
- roughMatchTcsLookup :: [Type] -> [RoughMatchLookupTc]
- instanceCantMatch :: [RoughMatchTc] -> [RoughMatchTc] -> Bool
- data RoughMap a
- emptyRM :: RoughMap a
- lookupRM :: [RoughMatchLookupTc] -> RoughMap a -> [a]
- lookupRM' :: [RoughMatchLookupTc] -> RoughMap a -> (Bag a, [a])
- insertRM :: [RoughMatchTc] -> a -> RoughMap a -> RoughMap a
- filterRM :: (a -> Bool) -> RoughMap a -> RoughMap a
- filterMatchingRM :: (a -> Bool) -> [RoughMatchTc] -> RoughMap a -> RoughMap a
- elemsRM :: RoughMap a -> [a]
- sizeRM :: RoughMap a -> Int
- foldRM :: (a -> b -> b) -> b -> RoughMap a -> b
- unionRM :: RoughMap a -> RoughMap a -> RoughMap a

# RoughMatchTc

data RoughMatchTc #

Constructors

RM_KnownTc Name |
RM_WildCard |

#### Instances

Instances details

Data RoughMatchTc # |
Instance details Defined in GHC.Core.RoughMap Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> RoughMatchTc -> c RoughMatchTc # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c RoughMatchTc # toConstr :: RoughMatchTc -> Constr # dataTypeOf :: RoughMatchTc -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c RoughMatchTc) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RoughMatchTc) # gmapT :: (forall b. Data b => b -> b) -> RoughMatchTc -> RoughMatchTc # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> RoughMatchTc -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> RoughMatchTc -> r # gmapQ :: (forall d. Data d => d -> u) -> RoughMatchTc -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> RoughMatchTc -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> RoughMatchTc -> m RoughMatchTc # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> RoughMatchTc -> m RoughMatchTc # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> RoughMatchTc -> m RoughMatchTc #
Outputable RoughMatchTc # |
Instance details Defined in GHC.Core.RoughMap Methods ppr :: RoughMatchTc -> SDoc #

isRoughWildcard :: RoughMatchTc -> Bool #

typeToRoughMatchTc :: Type -> RoughMatchTc #

data RoughMatchLookupTc #

Constructors

RML_KnownTc Name | The position only matches the specified KnownTc
RML_NoKnownTc | The position definitely doesn't match any KnownTc
RML_WildCard | The position can match anything

#### Instances

Instances details

Data RoughMatchLookupTc # |
Instance details Defined in GHC.Core.RoughMap Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> RoughMatchLookupTc -> c RoughMatchLookupTc # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c RoughMatchLookupTc # toConstr :: RoughMatchLookupTc -> Constr # dataTypeOf :: RoughMatchLookupTc -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c RoughMatchLookupTc) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RoughMatchLookupTc) # gmapT :: (forall b. Data b => b -> b) -> RoughMatchLookupTc -> RoughMatchLookupTc # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> RoughMatchLookupTc -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> RoughMatchLookupTc -> r # gmapQ :: (forall d. Data d => d -> u) -> RoughMatchLookupTc -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> RoughMatchLookupTc -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> RoughMatchLookupTc -> m RoughMatchLookupTc # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> RoughMatchLookupTc -> m RoughMatchLookupTc # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> RoughMatchLookupTc -> m RoughMatchLookupTc #
Outputable RoughMatchLookupTc # |
Instance details Defined in GHC.Core.RoughMap Methods ppr :: RoughMatchLookupTc -> SDoc #

typeToRoughMatchLookupTc :: Type -> RoughMatchLookupTc #

roughMatchTcToLookup :: RoughMatchTc -> RoughMatchLookupTc #

roughMatchTcs :: [Type] -> [RoughMatchTc] #

roughMatchTcsLookup :: [Type] -> [RoughMatchLookupTc] #

instanceCantMatch :: [RoughMatchTc] -> [RoughMatchTc] -> Bool #

# RoughMap

data RoughMap a #

Trie of `[RoughMatchTc]`

- Examples* `insert [OtherTc] 1 insert [OtherTc] 2 lookup [OtherTc] == [1,2]`

#### Instances

Instances details

Functor RoughMap # |
Instance details Defined in GHC.Core.RoughMap Methods fmap :: (a -> b) -> RoughMap a -> RoughMap b # (<$) :: a -> RoughMap b -> RoughMap a #
Outputable a => Outputable (RoughMap a) # |
Instance details Defined in GHC.Core.RoughMap Methods ppr :: RoughMap a -> SDoc #

emptyRM :: RoughMap a #

lookupRM :: [RoughMatchLookupTc] -> RoughMap a -> [a] #

Order of result is deterministic.

lookupRM' :: [RoughMatchLookupTc] -> RoughMap a -> (Bag a, [a]) #

N.B. Returns a `Bag` for matches, which allows us to avoid rebuilding all of the lists we find in `rm_empty`, which would otherwise be necessary due to `++` if we returned a list. We use a list for unifiers because the tail is computed lazily and we often only care about the first couple of potential unifiers. Constructing a bag forces the tail which performs much too much work.

See Note [Matching a RoughMap] See Note [Matches vs Unifiers]

insertRM :: [RoughMatchTc] -> a -> RoughMap a -> RoughMap a #

filterRM :: (a -> Bool) -> RoughMap a -> RoughMap a #

filterMatchingRM :: (a -> Bool) -> [RoughMatchTc] -> RoughMap a -> RoughMap a #

Filter all elements that might match a particular key with the given predicate.

elemsRM :: RoughMap a -> [a] #

sizeRM :: RoughMap a -> Int #

foldRM :: (a -> b -> b) -> b -> RoughMap a -> b #

unionRM :: RoughMap a -> RoughMap a -> RoughMap a #