datafix-0.0.1.0: Fixing data-flow problems

Copyright(c) Sebastian Graf 2017-2020
LicenseISC
Maintainersgraf1337@gmail.com
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Datafix.MonoMap

Description

A uniform interface for ordered maps that can be used to model monotone functions.

Synopsis

Documentation

class Foldable (MonoMap k) => MonoMapKey k where Source #

Chooses an appropriate MonoMap for a given key type.

MonoMaps 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.

Minimal complete definition

Nothing

Associated Types

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.

Methods

empty :: MonoMap k v Source #

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 #

Instances
MonoMapKey Int Source #

Delegates to IntMap.

Instance details

Defined in Datafix.MonoMap

Associated Types

type MonoMap Int = (r :: Type -> Type) Source #

Methods

empty :: MonoMap Int v Source #

singleton :: Int -> v -> MonoMap Int v Source #

insert :: Int -> v -> MonoMap Int v -> MonoMap Int v Source #

delete :: Int -> MonoMap Int v -> MonoMap Int v Source #

lookup :: Int -> MonoMap Int v -> Maybe v Source #

lookupLT :: Int -> MonoMap Int v -> [(Int, v)] Source #

lookupMin :: MonoMap Int v -> [(Int, v)] Source #

difference :: MonoMap Int a -> MonoMap Int b -> MonoMap Int a Source #

keys :: MonoMap Int a -> [Int] Source #

insertWith :: (v -> v -> v) -> Int -> v -> MonoMap Int v -> MonoMap Int v Source #

insertLookupWithKey :: (Int -> v -> v -> v) -> Int -> v -> MonoMap Int v -> (Maybe v, MonoMap Int v) Source #

updateLookupWithKey :: (Int -> v -> Maybe v) -> Int -> MonoMap Int v -> (Maybe v, MonoMap Int v) Source #

alter :: (Maybe v -> Maybe v) -> Int -> MonoMap Int v -> MonoMap Int v Source #

adjust :: (v -> v) -> Int -> MonoMap Int v -> MonoMap Int v Source #

MonoMapKey () Source #

Delegates to Maybe.

Instance details

Defined in Datafix.MonoMap

Associated Types

type MonoMap () = (r :: Type -> Type) Source #

Methods

empty :: MonoMap () v Source #

singleton :: () -> v -> MonoMap () v Source #

insert :: () -> v -> MonoMap () v -> MonoMap () v Source #

delete :: () -> MonoMap () v -> MonoMap () v Source #

lookup :: () -> MonoMap () v -> Maybe v Source #

lookupLT :: () -> MonoMap () v -> [((), v)] Source #

lookupMin :: MonoMap () v -> [((), v)] Source #

difference :: MonoMap () a -> MonoMap () b -> MonoMap () a Source #

keys :: MonoMap () a -> [()] Source #

insertWith :: (v -> v -> v) -> () -> v -> MonoMap () v -> MonoMap () v Source #

insertLookupWithKey :: (() -> v -> v -> v) -> () -> v -> MonoMap () v -> (Maybe v, MonoMap () v) Source #

updateLookupWithKey :: (() -> v -> Maybe v) -> () -> MonoMap () v -> (Maybe v, MonoMap () v) Source #

alter :: (Maybe v -> Maybe v) -> () -> MonoMap () v -> MonoMap () v Source #

adjust :: (v -> v) -> () -> MonoMap () v -> MonoMap () v Source #