tamarin-prover-utils-1.2.2: Utility library for the tamarin prover.

Copyright | (c) 2010 2011 Simon Meier
License | GPL v3 (see LICENSE)
Maintainer | Simon Meier <iridcode@gmail.com>
Safe Haskell | Safe
Language | Haskell98

Extension.Prelude

Description

Functions that could/should have made it into the Prelude or one of the base libraries

Synopsis

- implies :: Bool -> Bool -> Bool
- singleton :: a -> [a]
- unique :: Eq a => [a] -> Bool
- sortednub :: Ord a => [a] -> [a]
- sortednubBy :: (a -> a -> Ordering) -> [a] -> [a]
- sortednubOn :: Ord b => (a -> b) -> [a] -> [a]
- nubOn :: Eq b => (a -> b) -> [a] -> [a]
- groupOn :: Eq b => (a -> b) -> [a] -> [[a]]
- sortOn :: Ord b => (a -> b) -> [a] -> [a]
- sortOnMemo :: Ord b => (a -> b) -> [a] -> [a]
- groupSortOn :: Ord b => (a -> b) -> [a] -> [[a]]
- eqClasses :: Ord b => (a -> b) -> [a] -> [[a]]
- eqClassesBy :: (b -> b -> Ordering) -> (a -> b) -> [a] -> [[a]]
- splitBy :: (a -> Bool) -> [a] -> [[a]]
- choose :: Int -> [a] -> [[a]]
- leaveOneOut :: [a] -> [[a]]
- keepFirst :: (a -> a -> Bool) -> [a] -> [a]
- swap :: (a, b) -> (b, a)
- sortPair :: Ord a => (a, a) -> (a, a)
- isRight :: Either a b -> Bool
- isLeft :: Either a b -> Bool
- type Named a = (String, a)
- flushRightBy :: [a] -> Int -> [a] -> [a]
- flushRight :: Int -> String -> String
- flushLeftBy :: [a] -> Int -> [a] -> [a]
- flushLeft :: Int -> String -> String
- warning :: String -> String
- putErr :: String -> IO ()
- putErrLn :: String -> IO ()
- oneOfList :: Alternative f => [a] -> f a
- oneOfSet :: Alternative f => Set a -> f a
- oneOfMap :: Alternative f => Map k v -> f (k, v)
- ifM :: Monad m => m Bool -> m a -> m a -> m a
- errorFree :: MonadPlus m => [m a] -> m [a]
- errorFree1 :: MonadPlus m => [m a] -> m [a]
- unreachable :: String -> a

# Documentation

implies :: Bool -> Bool -> Bool #

singleton :: a -> [a] #

unique :: Eq a => [a] -> Bool #

check whether the given list contains no duplicates

sortednub :: Ord a => [a] -> [a] #

Sort list and remove duplicates. O(n*log n)

sortednubBy :: (a -> a -> Ordering) -> [a] -> [a] #

Sort a list according to a user-defined comparison function and remove duplicates.

sortednubOn :: Ord b => (a -> b) -> [a] -> [a] #

/O(n*log n)./ Sort list and remove duplicates with respect to a projection.

nubOn :: Eq b => (a -> b) -> [a] -> [a] #

Keep only the first element of elements having the same projected value

groupOn :: Eq b => (a -> b) -> [a] -> [[a]] #

/O(n)./ Group on a projection of the data to group

sortOn :: Ord b => (a -> b) -> [a] -> [a] #

sort on a projection of the data to sort

sortOnMemo :: Ord b => (a -> b) -> [a] -> [a] #

sort on a projection of the data to sort, memorizing the results of the projection in order to avoid recomputation.

groupSortOn :: Ord b => (a -> b) -> [a] -> [[a]] #

sort and group on a projection

eqClasses :: Ord b => (a -> b) -> [a] -> [[a]] #

partition the given set into equality classes with respect to the representative given by the projection function

eqClassesBy :: (b -> b -> Ordering) -> (a -> b) -> [a] -> [[a]] #

splitBy :: (a -> Bool) -> [a] -> [[a]] #

split a list into sublists whenever the predicate identifies an element as a separator. Note that the separator is not retained and a separator at the very end is ignored.

choose :: Int -> [a] -> [[a]] #

the list of all permutations of a given list permutations :: [a] -> [[a]] permutations [] = [[]] permutations zs = aux zs [] where aux [] _ = [] aux (x:xs) ys = [x:p | p <- permutations (xs++ys)] ++ aux xs (x:ys)

the list of all combinations of n elements of a list. E.g. choose 2 [1,2,3] = [[1,2],[1,3],[2,3]]

leaveOneOut :: [a] -> [[a]] #

build the list of lists each leaving another element out. (From left to right)

keepFirst :: (a -> a -> Bool) -> [a] -> [a] #

An element masks another element if the predicate is true. This function keeps only the elements not masked by a previous element in the list.

swap :: (a, b) -> (b, a) #

These functions were inspired by the ML library accompanying the Isabelle theorem prover (http://isabelle.in.tum.de/)

swap the elements of a pair

sortPair :: Ord a => (a, a) -> (a, a) #

sort the elements of a pair

isRight :: Either a b -> Bool #

isLeft :: Either a b -> Bool #

type Named a = (String, a) #

Name values of a given type

flushRightBy :: [a] -> Int -> [a] -> [a] #

Extend a list with the given separators to be flushed right.

flushRight :: Int -> String -> String #

Extend a string with spaces to be flushed right.

flushLeftBy :: [a] -> Int -> [a] -> [a] #

Extend a list with the given separators to be flushed left.

flushLeft :: Int -> String -> String #

Extend a string with spaces to be flushed left.

warning :: String -> String #

marks a string as being a warning

putErr :: String -> IO () #

abbreviation to print to stderr

putErrLn :: String -> IO () #

abbreviation to println to stderr

oneOfList :: Alternative f => [a] -> f a #

Inject the elements of a list as alternatives.

oneOfSet :: Alternative f => Set a -> f a #

Inject the elements of a set as alternatives.

oneOfMap :: Alternative f => Map k v -> f (k, v) #

Inject the elements of a map as alternatives.

ifM :: Monad m => m Bool -> m a -> m a -> m a #

A monadic if statement

errorFree :: MonadPlus m => [m a] -> m [a] #

Gather all error free computations.

errorFree1 :: MonadPlus m => [m a] -> m [a] #

Gather all error free computations and ensure that at least one was error free.

unreachable :: String -> a #

Mark a part of the code as unreachable.