Copyright | (c) Sebastian Graf 2017-2020 |
---|---|
License | ISC |
Maintainer | sgraf1337@gmail.com |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
A uniform interface for ordered maps that can be used to model monotone functions.
Synopsis
- class Foldable (MonoMap k) => MonoMapKey k where
- type MonoMap k = (r :: * -> *) | r -> k
- empty :: MonoMap k v
- singleton :: k -> v -> MonoMap k v
- insert :: k -> v -> MonoMap k v -> MonoMap k v
- delete :: k -> MonoMap k v -> MonoMap k v
- lookup :: k -> MonoMap k v -> Maybe v
- lookupLT :: k -> MonoMap k v -> [(k, v)]
- lookupMin :: MonoMap k v -> [(k, v)]
- difference :: MonoMap k a -> MonoMap k b -> MonoMap k a
- keys :: MonoMap k a -> [k]
- insertWith :: (v -> v -> v) -> k -> v -> MonoMap k v -> MonoMap k v
- insertLookupWithKey :: (k -> v -> v -> v) -> k -> v -> MonoMap k v -> (Maybe v, MonoMap k v)
- updateLookupWithKey :: (k -> v -> Maybe v) -> k -> MonoMap k v -> (Maybe v, MonoMap k v)
- alter :: (Maybe v -> Maybe v) -> k -> MonoMap k v -> MonoMap k v
- adjust :: (v -> v) -> k -> MonoMap k v -> MonoMap k v
Documentation
class Foldable (MonoMap k) => MonoMapKey k where Source #
Chooses an appropriate MonoMap
for a given key type.
MonoMap
s should all be ordered maps, which feature
efficient variants of the lookupLT
and lookupMin
combinators.
This unifies Data.Maybe, Data.IntMap.Strict, Data.Map.Strict and Data.POMap.Strict
under a common type class, for which instances can delegate to the
most efficient variant available.
Because of lookupLT
, this class lends itself well to approximating
monotone functions.
The default implementation delegates to POMap
, so when there is no
specially crafted map data-structure for your key type, all you need to do
is to make sure it satisfies PartialOrd
. Then you can do
>>>
import Data.IntSet
>>>
instance MonoMapKey IntSet
to make use of the default implementation.
Nothing
type MonoMap k = (r :: * -> *) | r -> k Source #
The particular ordered map implementation to use for the key type k
.
The default implementation delegates to POMap
.
empty :: MonoMap k v ~ POMap k v => MonoMap k v Source #
singleton :: k -> v -> MonoMap k v Source #
singleton :: MonoMap k v ~ POMap k v => k -> v -> MonoMap k v Source #
insert :: k -> v -> MonoMap k v -> MonoMap k v Source #
insert :: (MonoMap k v ~ POMap k v, PartialOrd k) => k -> v -> MonoMap k v -> MonoMap k v Source #
delete :: k -> MonoMap k v -> MonoMap k v Source #
delete :: (MonoMap k v ~ POMap k v, PartialOrd k) => k -> MonoMap k v -> MonoMap k v Source #
lookup :: k -> MonoMap k v -> Maybe v Source #
lookup :: (MonoMap k v ~ POMap k v, PartialOrd k) => k -> MonoMap k v -> Maybe v Source #
lookupLT :: k -> MonoMap k v -> [(k, v)] Source #
Key point of this interface! Note that it returns a list of
lower bounds, to account for the PartialOrd
case.
lookupLT :: (MonoMap k v ~ POMap k v, PartialOrd k) => k -> MonoMap k v -> [(k, v)] Source #
Key point of this interface! Note that it returns a list of
lower bounds, to account for the PartialOrd
case.
lookupMin :: MonoMap k v -> [(k, v)] Source #
lookupMin :: (MonoMap k v ~ POMap k v, PartialOrd k) => MonoMap k v -> [(k, v)] Source #
difference :: MonoMap k a -> MonoMap k b -> MonoMap k a Source #
difference :: (MonoMap k a ~ POMap k a, MonoMap k b ~ POMap k b, PartialOrd k) => MonoMap k a -> MonoMap k b -> MonoMap k a Source #
keys :: MonoMap k a -> [k] Source #
keys :: MonoMap k v ~ POMap k v => MonoMap k v -> [k] Source #
insertWith :: (v -> v -> v) -> k -> v -> MonoMap k v -> MonoMap k v Source #
insertWith :: (MonoMap k v ~ POMap k v, PartialOrd k) => (v -> v -> v) -> k -> v -> MonoMap k v -> MonoMap k v Source #
insertLookupWithKey :: (k -> v -> v -> v) -> k -> v -> MonoMap k v -> (Maybe v, MonoMap k v) Source #
insertLookupWithKey :: (MonoMap k v ~ POMap k v, PartialOrd k) => (k -> v -> v -> v) -> k -> v -> MonoMap k v -> (Maybe v, MonoMap k v) Source #
updateLookupWithKey :: (k -> v -> Maybe v) -> k -> MonoMap k v -> (Maybe v, MonoMap k v) Source #
updateLookupWithKey :: (MonoMap k v ~ POMap k v, PartialOrd k) => (k -> v -> Maybe v) -> k -> MonoMap k v -> (Maybe v, MonoMap k v) Source #
alter :: (Maybe v -> Maybe v) -> k -> MonoMap k v -> MonoMap k v Source #
alter :: (MonoMap k v ~ POMap k v, PartialOrd k) => (Maybe v -> Maybe v) -> k -> MonoMap k v -> MonoMap k v Source #
adjust :: (v -> v) -> k -> MonoMap k v -> MonoMap k v Source #
adjust :: (MonoMap k v ~ POMap k v, PartialOrd k) => (v -> v) -> k -> MonoMap k v -> MonoMap k v Source #