cryptol-2.11.0: Cryptol: The Language of Cryptography
Copyright(c) 2020 Galois Inc.
LicenseBSD3
Maintainercryptol@galois.com
Stabilityprovisional
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cryptol.Utils.RecordMap

Description

This module implements an "order insensitive" datastructure for record types and values. For most purposes, we want to deal with record fields in a canonical order; but for user interaction purposes, we generally want to display the fields in the order they were specified by the user (in source files, at the REPL, etc.).

Synopsis

Documentation

data RecordMap a b Source #

An "order insensitive" datastructure. The fields can be accessed either according to a "canonical" order, or based on a "display" order, which matches the order in which the fields were originally specified.

Instances

Instances details
Functor (RecordMap a) Source # 
Instance details

Defined in Cryptol.Utils.RecordMap

Methods

fmap :: (a0 -> b) -> RecordMap a a0 -> RecordMap a b #

(<$) :: a0 -> RecordMap a b -> RecordMap a a0 #

Foldable (RecordMap a) Source # 
Instance details

Defined in Cryptol.Utils.RecordMap

Methods

fold :: Monoid m => RecordMap a m -> m #

foldMap :: Monoid m => (a0 -> m) -> RecordMap a a0 -> m #

foldMap' :: Monoid m => (a0 -> m) -> RecordMap a a0 -> m #

foldr :: (a0 -> b -> b) -> b -> RecordMap a a0 -> b #

foldr' :: (a0 -> b -> b) -> b -> RecordMap a a0 -> b #

foldl :: (b -> a0 -> b) -> b -> RecordMap a a0 -> b #

foldl' :: (b -> a0 -> b) -> b -> RecordMap a a0 -> b #

foldr1 :: (a0 -> a0 -> a0) -> RecordMap a a0 -> a0 #

foldl1 :: (a0 -> a0 -> a0) -> RecordMap a a0 -> a0 #

toList :: RecordMap a a0 -> [a0] #

null :: RecordMap a a0 -> Bool #

length :: RecordMap a a0 -> Int #

elem :: Eq a0 => a0 -> RecordMap a a0 -> Bool #

maximum :: Ord a0 => RecordMap a a0 -> a0 #

minimum :: Ord a0 => RecordMap a a0 -> a0 #

sum :: Num a0 => RecordMap a a0 -> a0 #

product :: Num a0 => RecordMap a a0 -> a0 #

Traversable (RecordMap a) Source # 
Instance details

Defined in Cryptol.Utils.RecordMap

Methods

traverse :: Applicative f => (a0 -> f b) -> RecordMap a a0 -> f (RecordMap a b) #

sequenceA :: Applicative f => RecordMap a (f a0) -> f (RecordMap a a0) #

mapM :: Monad m => (a0 -> m b) -> RecordMap a a0 -> m (RecordMap a b) #

sequence :: Monad m => RecordMap a (m a0) -> m (RecordMap a a0) #

(Ord a, Eq b) => Eq (RecordMap a b) Source # 
Instance details

Defined in Cryptol.Utils.RecordMap

Methods

(==) :: RecordMap a b -> RecordMap a b -> Bool #

(/=) :: RecordMap a b -> RecordMap a b -> Bool #

(Ord a, Ord b) => Ord (RecordMap a b) Source # 
Instance details

Defined in Cryptol.Utils.RecordMap

Methods

compare :: RecordMap a b -> RecordMap a b -> Ordering #

(<) :: RecordMap a b -> RecordMap a b -> Bool #

(<=) :: RecordMap a b -> RecordMap a b -> Bool #

(>) :: RecordMap a b -> RecordMap a b -> Bool #

(>=) :: RecordMap a b -> RecordMap a b -> Bool #

max :: RecordMap a b -> RecordMap a b -> RecordMap a b #

min :: RecordMap a b -> RecordMap a b -> RecordMap a b #

(Show a, Ord a, Show b) => Show (RecordMap a b) Source # 
Instance details

Defined in Cryptol.Utils.RecordMap

Methods

showsPrec :: Int -> RecordMap a b -> ShowS #

show :: RecordMap a b -> String #

showList :: [RecordMap a b] -> ShowS #

(NFData a, NFData b) => NFData (RecordMap a b) Source # 
Instance details

Defined in Cryptol.Utils.RecordMap

Methods

rnf :: RecordMap a b -> () #

displayOrder :: RecordMap a b -> [a] Source #

The order in which the fields originally appeared.

canonicalFields :: RecordMap a b -> [(a, b)] Source #

Return a list of field/value pairs in canonical order.

displayFields :: (Show a, Ord a) => RecordMap a b -> [(a, b)] Source #

Return a list of field/value pairs in display order.

recordElements :: RecordMap a b -> [b] Source #

Retrieve the elements of the record in canonical order of the field names

fieldSet :: Ord a => RecordMap a b -> Set a Source #

Return the fields in this record as a set.

recordFromFields :: (Show a, Ord a) => [(a, b)] -> RecordMap a b Source #

Generate a record from a list of field/value pairs. Precondition: each field identifier appears at most once in the given list.

recordFromFieldsErr :: (Show a, Ord a) => [(a, b)] -> Either (a, b) (RecordMap a b) Source #

Generate a record from a list of field/value pairs. If any field name is repeated, the first repeated name/value pair is returned. Otherwise the constructed record is returned.

recordFromFieldsWithDisplay :: (Show a, Ord a) => [a] -> [(a, b)] -> RecordMap a b Source #

Generate a record from a list of field/value pairs, and also provide the "display" order for the fields directly. Precondition: each field identifier appears at most once in each list, and a field name appears in the display order iff it appears in the field list.

lookupField :: Ord a => a -> RecordMap a b -> Maybe b Source #

Lookup the value of a field

adjustField :: forall a b. Ord a => a -> (b -> b) -> RecordMap a b -> Maybe (RecordMap a b) Source #

Update the value of a field by applying the given function. If the field is not present in the record, return Nothing.

traverseRecordMap :: Applicative t => (a -> b -> t c) -> RecordMap a b -> t (RecordMap a c) Source #

Traverse the elements of the given record map in canonical order, applying the given action.

mapWithFieldName :: (a -> b -> c) -> RecordMap a b -> RecordMap a c Source #

Apply the given function to each element of a record.

zipRecordsM :: forall t a b c d. (Ord a, Monad t) => (a -> b -> c -> t d) -> RecordMap a b -> RecordMap a c -> t (Either (Either a a) (RecordMap a d)) Source #

Zip together the fields of two records using the provided action. If some field is present in one record, but not the other, an Either a a will be returned, indicating which record is missing the field, and returning the name of the missing field.

The displayOrder of the resulting record will be taken from the first argument (rather arbitrarily).

zipRecords :: forall a b c d. Ord a => (a -> b -> c -> d) -> RecordMap a b -> RecordMap a c -> Either (Either a a) (RecordMap a d) Source #

Pure version of zipRecordsM

recordMapAccum :: (a -> b -> (a, c)) -> a -> RecordMap k b -> (a, RecordMap k c) Source #

The function recordMapAccum threads an accumulating argument through the map in canonical order of fields.