dependent-enummap-0.1.0.0: A generalisation of EnumMap to dependent types
Safe HaskellNone
LanguageHaskell2010

Data.Dependent.EnumMap.Strict.Internal

Synopsis

Documentation

data KV (k :: kind -> Type) (v :: kind -> Type) Source #

Constructors

KV !(Enum1Info k) !(v a) 

newtype DEnumMap (k :: kind -> Type) (v :: kind -> Type) Source #

Constructors

DEnumMap (IntMap (KV k v)) 

Instances

Instances details
(Enum1 k, forall (a :: kind). Show (k a), forall (a :: kind). Show (v a)) => Show (DEnumMap k v) Source # 
Instance details

Defined in Data.Dependent.EnumMap.Strict.Internal

Methods

showsPrec :: Int -> DEnumMap k v -> ShowS #

show :: DEnumMap k v -> String #

showList :: [DEnumMap k v] -> ShowS #

class Enum1 (f :: k -> Type) where Source #

This class attempts to generalise Enum to indexed data types: data types with a GADT-like type parameter. Conversion to an Int naturally loses type information, and furthermore it is common to actually need some additional data alongside the Int to be able to reconstruct the original (in toEnum1). This additional data lives in Enum1Info. The laws are:

Unique IDs
If fst (fromEnum1 x) == fst (fromEnum1 y) then testEquality x y == Just Refl && x == y
Persistent IDs
fst (fromEnum1 (uncurry toEnum1 (fromEnum1 x))) == fst (fromEnum1 x)

The "Unique IDs" law states that if the IDs of two values are equal, then the values themselves must have the same type index, and furthermore be equal. If f does not implement TestEquality or Eq, the law should morally hold (but most of the API will be unusable).

The "Persistent IDs" law states that reconstructing a value using toEnum1 does not change its ID.

Note: The methods on DEnumMap attempt to check these laws using assert assertions (which are by default disabled when optimisations are on!), but full consistency cannot always be checked; if you break these laws in a sufficiently clever way, the internals of DEnumMap may unsafeCoerce unequal things and engage nasal demons, including crashes and worse.

Associated Types

type Enum1Info (f :: k -> Type) Source #

Methods

fromEnum1 :: forall (a :: k). f a -> (Int, Enum1Info f) Source #

toEnum1 :: Int -> Enum1Info f -> Some f Source #

dSumToKV :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). Enum1 k => DSum k v -> (Int, KV k v) Source #

kVToDSum :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). Enum1 k2 => (Int, KV k2 v) -> DSum k2 v Source #

Assumes that the input was obtained via fromEnum1.

Construction

empty :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). DEnumMap k v Source #

singleton :: forall {kind} k (a :: kind) v. Enum1 k => k a -> v a -> DEnumMap k v Source #

From Unordered Lists

fromList :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). Enum1 k => [DSum k v] -> DEnumMap k v Source #

fromListWith :: forall {kind} (k :: kind -> Type) v. (Enum1 k, TestEquality k) => (forall (a :: kind). v a -> v a -> v a) -> [DSum k v] -> DEnumMap k v Source #

fromListWithKey :: (Enum1 k, TestEquality k) => (forall (a :: kind). k a -> v a -> v a -> v a) -> [DSum k v] -> DEnumMap k v Source #

From Ascending Lists

fromAscList :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). Enum1 k => [DSum k v] -> DEnumMap k v Source #

fromAscListWith :: forall {kind} (k :: kind -> Type) v. (Enum1 k, TestEquality k) => (forall (a :: kind). v a -> v a -> v a) -> [DSum k v] -> DEnumMap k v Source #

fromAscListWithKey :: (Enum1 k, TestEquality k) => (forall (a :: kind). k a -> v a -> v a -> v a) -> [DSum k v] -> DEnumMap k v Source #

fromDistinctAscList :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). Enum1 k => [DSum k v] -> DEnumMap k v Source #

Insertion

insert :: forall {kind} k (a :: kind) v. Enum1 k => k a -> v a -> DEnumMap k v -> DEnumMap k v Source #

insertWith :: forall {kind} k v (a :: kind). (Enum1 k, TestEquality k) => (v a -> v a -> v a) -> k a -> v a -> DEnumMap k v -> DEnumMap k v Source #

insertWithKey :: forall {kind} k (a :: kind) v. (Enum1 k, TestEquality k) => (k a -> v a -> v a -> v a) -> k a -> v a -> DEnumMap k v -> DEnumMap k v Source #

insertLookupWithKey :: forall {kind} k (a :: kind) v. (Enum1 k, TestEquality k) => (k a -> v a -> v a -> v a) -> k a -> v a -> DEnumMap k v -> (Maybe (v a), DEnumMap k v) Source #

Deletion/Update

delete :: forall {kind} k (a :: kind) (v :: kind -> Type). Enum1 k => k a -> DEnumMap k v -> DEnumMap k v Source #

adjust :: forall {kind} k v (a :: kind). (Enum1 k, TestEquality k) => (v a -> v a) -> k a -> DEnumMap k v -> DEnumMap k v Source #

adjustWithKey :: forall {kind} k (a :: kind) v. (Enum1 k, TestEquality k) => (k a -> v a -> v a) -> k a -> DEnumMap k v -> DEnumMap k v Source #

update :: forall {kind} k v (a :: kind). (Enum1 k, TestEquality k) => (v a -> Maybe (v a)) -> k a -> DEnumMap k v -> DEnumMap k v Source #

updateWithKey :: forall {kind} k (a :: kind) v. (Enum1 k, TestEquality k) => (k a -> v a -> Maybe (v a)) -> k a -> DEnumMap k v -> DEnumMap k v Source #

updateLookupWithKey :: forall {kind} k (a :: kind) v. (Enum1 k, TestEquality k) => (k a -> v a -> Maybe (v a)) -> k a -> DEnumMap k v -> (Maybe (v a), DEnumMap k v) Source #

alter :: forall {kind} k v (a :: kind). (Enum1 k, TestEquality k) => (Maybe (v a) -> Maybe (v a)) -> k a -> DEnumMap k v -> DEnumMap k v Source #

alterF :: forall {kind} k v (a :: kind) f. (Functor f, Enum1 k, TestEquality k) => (Maybe (v a) -> f (Maybe (v a))) -> k a -> DEnumMap k v -> f (DEnumMap k v) Source #

Query

Lookup

lookup :: forall {kind} k (a :: kind) v. (Enum1 k, TestEquality k) => k a -> DEnumMap k v -> Maybe (v a) Source #

(!?) :: forall {kind} k v (a :: kind). (Enum1 k, TestEquality k) => DEnumMap k v -> k a -> Maybe (v a) Source #

findWithDefault :: forall {kind} k v (a :: kind). (Enum1 k, TestEquality k) => v a -> k a -> DEnumMap k v -> v a Source #

find :: forall {kind} k (a :: kind) v. (Enum1 k, TestEquality k) => k a -> DEnumMap k v -> v a Source #

(!) :: forall {kind} k v (a :: kind). (Enum1 k, TestEquality k) => DEnumMap k v -> k a -> v a Source #

member :: forall {kind} k (a :: kind) (v :: kind -> Type). Enum1 k => k a -> DEnumMap k v -> Bool Source #

notMember :: forall {kind} k (a :: kind) (v :: kind -> Type). Enum1 k => k a -> DEnumMap k v -> Bool Source #

lookupLT :: forall {k1} k2 (a :: k1) (v :: k1 -> Type). Enum1 k2 => k2 a -> DEnumMap k2 v -> Maybe (DSum k2 v) Source #

lookupGT :: forall {k1} k2 (a :: k1) (v :: k1 -> Type). Enum1 k2 => k2 a -> DEnumMap k2 v -> Maybe (DSum k2 v) Source #

lookupLE :: forall {k1} k2 (a :: k1) (v :: k1 -> Type). Enum1 k2 => k2 a -> DEnumMap k2 v -> Maybe (DSum k2 v) Source #

lookupGE :: forall {k1} k2 (a :: k1) (v :: k1 -> Type). Enum1 k2 => k2 a -> DEnumMap k2 v -> Maybe (DSum k2 v) Source #

Size

null :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). DEnumMap k v -> Bool Source #

size :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). DEnumMap k v -> Int Source #

Combine

Union

union :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). (Enum1 k, TestEquality k) => DEnumMap k v -> DEnumMap k v -> DEnumMap k v Source #

unionWith :: forall {kind} (k :: kind -> Type) v. (Enum1 k, TestEquality k) => (forall (a :: kind). v a -> v a -> v a) -> DEnumMap k v -> DEnumMap k v -> DEnumMap k v Source #

unionWithKey :: (Enum1 k, TestEquality k) => (forall (a :: kind). k a -> v a -> v a -> v a) -> DEnumMap k v -> DEnumMap k v -> DEnumMap k v Source #

unions :: forall {kind} f (k :: kind -> Type) (v :: kind -> Type). (Foldable f, Enum1 k, TestEquality k) => f (DEnumMap k v) -> DEnumMap k v Source #

unionsWith :: forall {kind} f (k :: kind -> Type) v. (Foldable f, Enum1 k, TestEquality k) => (forall (a :: kind). v a -> v a -> v a) -> f (DEnumMap k v) -> DEnumMap k v Source #

Difference

difference :: forall {kind} (k :: kind -> Type) (v1 :: kind -> Type) (v2 :: kind -> Type). DEnumMap k v1 -> DEnumMap k v2 -> DEnumMap k v1 Source #

(\\) :: forall {kind} (k :: kind -> Type) (v1 :: kind -> Type) (v2 :: kind -> Type). DEnumMap k v1 -> DEnumMap k v2 -> DEnumMap k v1 Source #

differenceWith :: forall {kind} (k :: kind -> Type) v1 v2. (Enum1 k, TestEquality k) => (forall (a :: kind). v1 a -> v2 a -> Maybe (v1 a)) -> DEnumMap k v1 -> DEnumMap k v2 -> DEnumMap k v1 Source #

differenceWithKey :: (Enum1 k, TestEquality k) => (forall (a :: kind). k a -> v1 a -> v2 a -> Maybe (v1 a)) -> DEnumMap k v1 -> DEnumMap k v2 -> DEnumMap k v1 Source #

differenceWithKey' :: forall {kind1} {kind2} k1 k2 v1 v2. (Enum1 k1, Enum1 k2) => (forall (a :: kind1) (b :: kind2). k1 a -> v1 a -> k2 b -> v2 b -> Maybe (v1 a)) -> DEnumMap k1 v1 -> DEnumMap k2 v2 -> DEnumMap k1 v1 Source #

Because the underlying maps are keyed on integers, it is possible to subtract a map from another even if the key types differ. This function assumes that the Int identifiers of k1 and k2 are compatible, i.e. that "2" in k1 somehow means the same thing as "2" in k2.

Because the key types are different, there is no guarantee whatsoever (even not by Enum1 laws) that equal key IDs in k1 and k2 actually have the same type index (a). Hence, the combining function gets key-value pairs with potentially distinct type indices.

Intersection

intersection :: forall {kind} (k :: kind -> Type) (v1 :: kind -> Type) (v2 :: kind -> Type). DEnumMap k v1 -> DEnumMap k v2 -> DEnumMap k v1 Source #

intersectionWith :: forall {kind} (k :: kind -> Type) v1 v2 v3. (Enum1 k, TestEquality k) => (forall (a :: kind). v1 a -> v2 a -> v3 a) -> DEnumMap k v1 -> DEnumMap k v2 -> DEnumMap k v3 Source #

intersectionWithKey :: (Enum1 k, TestEquality k) => (forall (a :: kind). k a -> v1 a -> v2 a -> v3 a) -> DEnumMap k v1 -> DEnumMap k v2 -> DEnumMap k v3 Source #

intersectionWithKey' :: forall {kind1} {kind2} k1 k2 v1 v2 v3. (Enum1 k1, Enum1 k2) => (forall (a :: kind1) (b :: kind2). k1 a -> v1 a -> k2 b -> v2 b -> v3 a) -> DEnumMap k1 v1 -> DEnumMap k2 v2 -> DEnumMap k1 v3 Source #

Generalises intersectionWithKey in the same way as differenceWithKey' generalises differenceWithKey.

Disjoint

disjoint :: forall {kind} (k :: kind -> Type) (v1 :: kind -> Type) (v2 :: kind -> Type). DEnumMap k v1 -> DEnumMap k v2 -> Bool Source #

Compose

compose :: forall {kind} (k2 :: kind -> Type) (v :: kind -> Type) (k1 :: kind -> Type). (Enum1 k2, TestEquality k2) => DEnumMap k2 v -> DEnumMap k1 k2 -> DEnumMap k1 v Source #

Universal combining function

mergeWithKey :: (Enum1 k, TestEquality k) => (forall (a :: kind). k a -> v1 a -> v2 a -> Maybe (v3 a)) -> (DEnumMap k v1 -> DEnumMap k v3) -> (DEnumMap k v2 -> DEnumMap k v3) -> DEnumMap k v1 -> DEnumMap k v2 -> DEnumMap k v3 Source #

Traversal

Map

map :: forall {kind} (k :: kind -> Type) v1 v2. Enum1 k => (forall (a :: kind). v1 a -> v2 a) -> DEnumMap k v1 -> DEnumMap k v2 Source #

mapWithKey :: Enum1 k => (forall (a :: kind). k a -> v1 a -> v2 a) -> DEnumMap k v1 -> DEnumMap k v2 Source #

traverseWithKey :: forall {kind} f k v1 v2. (Applicative f, Enum1 k) => (forall (a :: kind). k a -> v1 a -> f (v2 a)) -> DEnumMap k v1 -> f (DEnumMap k v2) Source #

traverseMaybeWithKey :: forall {kind} f k v1 v2. (Applicative f, Enum1 k) => (forall (a :: kind). k a -> v1 a -> f (Maybe (v2 a))) -> DEnumMap k v1 -> f (DEnumMap k v2) Source #

mapAccum :: forall {kind} (k :: kind -> Type) acc v1 v2. Enum1 k => (forall (a :: kind). acc -> v1 a -> (acc, v2 a)) -> acc -> DEnumMap k v1 -> (acc, DEnumMap k v2) Source #

mapAccumWithKey :: Enum1 k => (forall (a :: kind). acc -> k a -> v1 a -> (acc, v2 a)) -> acc -> DEnumMap k v1 -> (acc, DEnumMap k v2) Source #

mapAccumRWithKey :: Enum1 k => (forall (a :: kind). acc -> k a -> v1 a -> (acc, v2 a)) -> acc -> DEnumMap k v1 -> (acc, DEnumMap k v2) Source #

Folds

foldr :: forall {kind} v acc (k :: kind -> Type). (forall (a :: kind). v a -> acc -> acc) -> acc -> DEnumMap k v -> acc Source #

foldl :: forall {kind} acc v (k :: kind -> Type). (forall (a :: kind). acc -> v a -> acc) -> acc -> DEnumMap k v -> acc Source #

foldrWithKey :: Enum1 k => (forall (a :: kind). k a -> v a -> acc -> acc) -> acc -> DEnumMap k v -> acc Source #

foldlWithKey :: Enum1 k => (forall (a :: kind). acc -> k a -> v a -> acc) -> acc -> DEnumMap k v -> acc Source #

foldMapWithKey :: forall {kind} m k v. (Monoid m, Enum1 k) => (forall (a :: kind). k a -> v a -> m) -> DEnumMap k v -> m Source #

Strict folds

foldr' :: forall {kind} v acc (k :: kind -> Type). (forall (a :: kind). v a -> acc -> acc) -> acc -> DEnumMap k v -> acc Source #

foldl' :: forall {kind} acc v (k :: kind -> Type). (forall (a :: kind). acc -> v a -> acc) -> acc -> DEnumMap k v -> acc Source #

foldrWithKey' :: Enum1 k => (forall (a :: kind). k a -> v a -> acc -> acc) -> acc -> DEnumMap k v -> acc Source #

foldlWithKey' :: Enum1 k => (forall (a :: kind). acc -> k a -> v a -> acc) -> acc -> DEnumMap k v -> acc Source #

Conversion

elems :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). DEnumMap k2 v -> [Some v] Source #

keys :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). Enum1 k2 => DEnumMap k2 v -> [Some k2] Source #

assocs :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). Enum1 k2 => DEnumMap k2 v -> [DSum k2 v] Source #

Lists

toList :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). Enum1 k2 => DEnumMap k2 v -> [DSum k2 v] Source #

Ordered lists

toAscList :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). Enum1 k2 => DEnumMap k2 v -> [DSum k2 v] Source #

toDescList :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). Enum1 k2 => DEnumMap k2 v -> [DSum k2 v] Source #

Filter

filter :: forall {kind} v (k :: kind -> Type). (forall (a :: kind). v a -> Bool) -> DEnumMap k v -> DEnumMap k v Source #

filterWithKey :: Enum1 k => (forall (a :: kind). k a -> v a -> Bool) -> DEnumMap k v -> DEnumMap k v Source #

partition :: forall {kind} v (k :: kind -> Type). (forall (a :: kind). v a -> Bool) -> DEnumMap k v -> (DEnumMap k v, DEnumMap k v) Source #

partitionWithKey :: Enum1 k => (forall (a :: kind). k a -> v a -> Bool) -> DEnumMap k v -> (DEnumMap k v, DEnumMap k v) Source #

takeWhileAntitone :: forall {kind} k (v :: kind -> Type). Enum1 k => (forall (a :: kind). k a -> Bool) -> DEnumMap k v -> DEnumMap k v Source #

\(O(\min(n,W)^2)\). Because of the lack of a takeWhileAntitoneWithValue operation on IntMap, this function performs additional lookups to reconstruct the full keys to pass to the predicate, resulting in a somewhat worse complexity than takeWhileAntitone.

dropWhileAntitone :: forall {kind} k (v :: kind -> Type). Enum1 k => (forall (a :: kind). k a -> Bool) -> DEnumMap k v -> DEnumMap k v Source #

\(O(\min(n,W)^2)\). See takeWhileAntitone.

spanAntitone :: forall {kind} k (v :: kind -> Type). Enum1 k => (forall (a :: kind). k a -> Bool) -> DEnumMap k v -> (DEnumMap k v, DEnumMap k v) Source #

\(O(\min(n,W)^2)\). See takeWhileAntitone.

mapMaybe :: forall {kind} (k :: kind -> Type) v1 v2. Enum1 k => (forall (a :: kind). v1 a -> Maybe (v2 a)) -> DEnumMap k v1 -> DEnumMap k v2 Source #

mapMaybeWithKey :: Enum1 k => (forall (a :: kind). k a -> v1 a -> Maybe (v2 a)) -> DEnumMap k v1 -> DEnumMap k v2 Source #

mapEither :: forall {kind} (k :: kind -> Type) v1 v2 v3. Enum1 k => (forall (a :: kind). v1 a -> Either (v2 a) (v3 a)) -> DEnumMap k v1 -> (DEnumMap k v2, DEnumMap k v3) Source #

mapEitherWithKey :: Enum1 k => (forall (a :: kind). k a -> v1 a -> Either (v2 a) (v3 a)) -> DEnumMap k v1 -> (DEnumMap k v2, DEnumMap k v3) Source #

split :: forall {kind} k (a :: kind) (v :: kind -> Type). Enum1 k => k a -> DEnumMap k v -> (DEnumMap k v, DEnumMap k v) Source #

splitLookup :: forall {kind} k (a :: kind) v. Enum1 k => k a -> DEnumMap k v -> (DEnumMap k v, Maybe (v a), DEnumMap k v) Source #

splitRoot :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). DEnumMap k v -> [DEnumMap k v] Source #

Submap

isSubmapOf :: forall {kind} (v :: kind -> Type) (k :: kind -> Type). (forall (a :: kind). Eq (v a)) => DEnumMap k v -> DEnumMap k v -> Bool Source #

isSubmapOfBy :: forall {kind} v1 v2 (k :: kind -> Type). (forall (a :: kind). v1 a -> v2 a -> Bool) -> DEnumMap k v1 -> DEnumMap k v2 -> Bool Source #

isProperSubmapOf :: forall {kind} (v :: kind -> Type) (k :: kind -> Type). (forall (a :: kind). Eq (v a)) => DEnumMap k v -> DEnumMap k v -> Bool Source #

isProperSubmapOfBy :: forall {kind} v1 v2 (k :: kind -> Type). (forall (a :: kind). v1 a -> v2 a -> Bool) -> DEnumMap k v1 -> DEnumMap k v2 -> Bool Source #

Min/Max

lookupMin :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). Enum1 k2 => DEnumMap k2 v -> Maybe (DSum k2 v) Source #

lookupMax :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). Enum1 k2 => DEnumMap k2 v -> Maybe (DSum k2 v) Source #

findMin :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). Enum1 k2 => DEnumMap k2 v -> DSum k2 v Source #

findMax :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). Enum1 k2 => DEnumMap k2 v -> DSum k2 v Source #

deleteMin :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). DEnumMap k v -> DEnumMap k v Source #

deleteMax :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). DEnumMap k v -> DEnumMap k v Source #

deleteFindMin :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). Enum1 k => DEnumMap k v -> (DSum k v, DEnumMap k v) Source #

deleteFindMax :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). Enum1 k => DEnumMap k v -> (DSum k v, DEnumMap k v) Source #

updateMin :: forall {kind} (k :: kind -> Type) v. Enum1 k => (forall (a :: kind). v a -> Maybe (v a)) -> DEnumMap k v -> DEnumMap k v Source #

updateMinWithKey :: Enum1 k => (forall (a :: kind). k a -> v a -> Maybe (v a)) -> DEnumMap k v -> DEnumMap k v Source #

updateMax :: forall {kind} (k :: kind -> Type) v. Enum1 k => (forall (a :: kind). v a -> Maybe (v a)) -> DEnumMap k v -> DEnumMap k v Source #

updateMaxWithKey :: Enum1 k => (forall (a :: kind). k a -> v a -> Maybe (v a)) -> DEnumMap k v -> DEnumMap k v Source #

minView :: forall {kind} (k :: kind -> Type) v (a :: kind). DEnumMap k v -> Maybe (v a, DEnumMap k v) Source #

maxView :: forall {kind} (k :: kind -> Type) v (a :: kind). DEnumMap k v -> Maybe (v a, DEnumMap k v) Source #

minViewWithKey :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). Enum1 k => DEnumMap k v -> Maybe (DSum k v, DEnumMap k v) Source #

maxViewWithKey :: forall {kind} (k :: kind -> Type) (v :: kind -> Type). Enum1 k => DEnumMap k v -> Maybe (DSum k v, DEnumMap k v) Source #

Helpers

coe1 :: forall {k} v (a :: k) (b :: k). v a -> v b Source #

typeCheck1 :: forall {k1} k2 (a :: k1) r. (Enum1 k2, TestEquality k2) => k2 a -> Int -> Enum1Info k2 -> r -> r Source #

typeCheck2 :: forall {k1} (k2 :: k1 -> Type) proxy r. (Enum1 k2, TestEquality k2) => proxy k2 -> Int -> Enum1Info k2 -> Enum1Info k2 -> r -> r Source #