swish-0.7.0.1: A semantic web toolkit.

PortabilityA lot of LANGUAGE extensions...
Stabilityexperimental
MaintainerDouglas Burke
Safe HaskellSafe-Infered

Data.LookupMap

Description

This module defines a lookup table format and associated functions used by the graph matching code.

Synopsis

Documentation

class (Eq k, Show k) => LookupEntryClass a k v | a -> k, a -> v whereSource

LookupEntryClass defines essential functions of any datatype that can be used to make a LookupMap.

Minimal definition: newEntry and keyVal

Methods

newEntry :: (k, v) -> aSource

keyVal :: a -> (k, v)Source

entryKey :: a -> kSource

entryVal :: a -> vSource

entryEq :: Eq v => a -> a -> BoolSource

entryShow :: Show v => a -> StringSource

kmap :: LookupEntryClass a2 k2 v => (k -> k2) -> a -> a2Source

vmap :: LookupEntryClass a2 k v2 => (v -> v2) -> a -> a2Source

Instances

LookupEntryClass ClassRestriction ScopedName ClassRestriction 
LookupEntryClass RevNamespace URI (Maybe Text) 
LookupEntryClass NamedGraph ScopedName [RDFGraph] 
LookupEntryClass Namespace (Maybe Text) URI 
LookupEntryClass (Rule ex) ScopedName (Rule ex) 
LookupEntryClass (Formula ex) ScopedName (Formula ex) 
LookupEntryClass (Ruleset ex) Namespace (Ruleset ex) 
LookupEntryClass (DatatypeRel vt) ScopedName (DatatypeRel vt) 
(Eq k, Show k) => LookupEntryClass (k, v) k v

Predefine a pair of appropriate values as a valid lookup table entry (i.e. an instance of LookupEntryClass).

(Label lb, Eq lb, Show lb, Eq lv, Show lv) => LookupEntryClass (GenLabelEntry lb lv) lb lv 
Label lb => LookupEntryClass (LookupFormula lb (NSGraph lb)) lb (NSGraph lb) 
LookupEntryClass (OpenVarBindingModify a b) ScopedName (OpenVarBindingModify a b)

Allow an OpenVarBindingModify value to be accessed using a LookupMap.

LookupEntryClass (VarBindingModify a b) ScopedName (VarBindingModify a b)

Allow a VarBindingModify value to be accessed using a LookupMap.

LookupEntryClass (DatatypeMod vt lb vn) ScopedName (DatatypeMod vt lb vn) 
LookupEntryClass (Datatype ex lb vn) ScopedName (Datatype ex lb vn) 

data LookupMap a Source

Define a lookup map based on a list of values.

Constructors

LookupMap [a] 

Instances

Functor LookupMap 
Foldable LookupMap 
Traversable LookupMap 
Eq a => Eq (LookupMap a)

Define equality of LookupMap values based on equality of entries.

(This is possibly a poor definition, as it is dependent on ordering of list members. But it passes all current test cases, and is used only for testing.)

Show a => Show (LookupMap a)

Define Show instance for LookupMap based on Showing the list of entries.

emptyLookupMap :: LookupEntryClass a k v => LookupMap aSource

Empty lookup map of arbitrary (i.e. polymorphic) type.

makeLookupMapSource

Arguments

:: LookupEntryClass a k v 
=> [a]

This list is not checked for duplicate entries, or entries with the same key but different values.

-> LookupMap a 

Function to create a LookupMap from a list of entries.

listLookupMap :: LookupEntryClass a k v => LookupMap a -> [a]Source

Returns a list of lookup map entries.

reverseLookupMap :: (LookupEntryClass a1 b c, LookupEntryClass a2 c b) => LookupMap a1 -> LookupMap a2Source

Given a lookup map, return a new map that can be used in the opposite direction of lookup.

keyOrder :: (LookupEntryClass a k v, Ord k) => a -> a -> OrderingSource

Given a pair of lookup entry values, return the ordering of their key values.

mapFindSource

Arguments

:: LookupEntryClass a k v 
=> v

The default value.

-> k 
-> LookupMap a 
-> v 

Find key in lookup map and return corresponding value, otherwise return default supplied.

mapFindMaybe :: LookupEntryClass a k v => k -> LookupMap a -> Maybe vSource

Find key in lookup map and return Just the corresponding value, otherwise return Nothing.

mapContains :: LookupEntryClass a k v => LookupMap a -> k -> BoolSource

Test to see if key is present in the supplied map

mapReplace :: LookupEntryClass a k v => LookupMap a -> a -> LookupMap aSource

Replace the first occurrence of a key a with a new key-value pair, or add a new key-value pair if the supplied key is not already present.

mapReplaceAll :: LookupEntryClass a k v => LookupMap a -> a -> LookupMap aSource

Replace all occurrence of a key a with a new key-value pair.

The resulting lookup map has the same form as the original in all other respects.

mapReplaceMap :: LookupEntryClass a k v => LookupMap a -> LookupMap a -> LookupMap aSource

Replace any occurrence of a key in the first argument with a corresponding key-value pair from the second argument, if present.

This could be implemented by multiple applications of mapReplaceAll, but is arranged differently so that only one new LookupMap value is created.

Note: keys in the new map that are not present in the old map are not included in the result map

mapAdd :: LookupMap a -> a -> LookupMap aSource

Add supplied key-value pair to the lookup map.

This is effectively an optimized case of mapReplace or mapAddIfNew, where the caller guarantees to avoid duplicate key values.

mapAddIfNew :: LookupEntryClass a k v => LookupMap a -> a -> LookupMap aSource

Add supplied key-value pair to the lookup map, only if the key value is not already present.

mapDelete :: LookupEntryClass a k v => LookupMap a -> k -> LookupMap aSource

Delete the first occurrence of the key from the lookup map.

If the key does not exist in the map then no change is made.

mapDeleteAll :: LookupEntryClass a k v => LookupMap a -> k -> LookupMap aSource

Delete all occurrences of the key from the lookup map.

mapEq :: (LookupEntryClass a k v, Eq v) => LookupMap a -> LookupMap a -> BoolSource

Compare two lookup maps for equality.

Two maps are equal if they have the same set of keys, and if each key maps to an equivalent value. This is only guaranteed if the maps do not contain duplicate entries.

mapKeys :: LookupEntryClass a k v => LookupMap a -> [k]Source

Return the list of distinct keys in a supplied LookupMap

mapVals :: (Eq v, LookupEntryClass a k v) => LookupMap a -> [v]Source

Return list of distinct values in a supplied LookupMap

mapMerge :: (LookupEntryClass a k v, Eq a, Show a, Ord k) => LookupMap a -> LookupMap a -> LookupMap aSource

Merge two lookup maps, ensuring that if the same key appears in both maps it is associated with the same value.