Basic string-manipulation and other functions they forgot to put in the standard prelude.
- trimTrailing :: String -> String
- trimLeading :: String -> String
- trimSpaces :: String -> String
- padToLength :: Int -> String -> String
- monadDot :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
- simpleSplit :: (a -> Bool) -> [a] -> [[a]]
- findJust :: (a -> Maybe b) -> [a] -> Maybe b
- insertOrdLt :: Ord a => a -> [a] -> [a]
- insertOrdGt :: Ord a => a -> [a] -> [a]
- insertOrd :: (a -> a -> Bool) -> a -> [a] -> [a]
- insertOrdAlternate :: (a -> a -> Ordering) -> a -> (a -> a) -> [a] -> [a]
- bottom :: a
- readCheck :: Read a => String -> Maybe a
- chop :: Int -> [a] -> Maybe [a]
- pairList :: a -> [b] -> [(a, b)]
- lastOpt :: [a] -> Maybe a
- isPrefix :: Eq a => [a] -> [a] -> Maybe [a]
- class HasCoMapIO option where
- class HasMapIO option where
- class HasMapMonadic h where
- mapMonadic :: Monad m => (a -> m b) -> h a -> m (h b)
- mapPartialM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b]
- splitByChar :: Char -> String -> [String]
- unsplitByChar :: Char -> [String] -> String
- unsplitByChar0 :: Char -> [String] -> String
- splitToChar :: Char -> String -> Maybe (String, String)
- splitToElem :: (a -> Bool) -> [a] -> Maybe ([a], [a])
- splitToElemGeneral :: (a -> Bool) -> [a] -> Maybe ([a], a, [a])
- deleteFirst :: (a -> Bool) -> [a] -> [a]
- deleteFirstOpt :: (a -> Bool) -> [a] -> [a]
- deleteAndFindFirst :: (a -> Bool) -> [a] -> (a, [a])
- deleteAndFindFirstOpt :: (a -> Bool) -> [a] -> Maybe (a, [a])
- divideList :: (a -> Either b c) -> [a] -> ([b], [c])
- treeFold :: (ancestorInfo -> state -> node -> (ancestorInfo, state, [node])) -> ancestorInfo -> state -> node -> state
- treeFoldM :: Monad m => (ancestorInfo -> state -> node -> m (ancestorInfo, state, [node])) -> ancestorInfo -> state -> node -> m state
- mapEq :: Eq a => (b -> a) -> b -> b -> Bool
- mapOrd :: Ord a => (b -> a) -> b -> b -> Ordering
- type BreakFn = forall other. String -> other
- addFallOut :: (BreakFn -> IO a) -> IO (Either String a)
- addFallOutWE :: (BreakFn -> IO a) -> IO (WithError a)
- addSimpleFallOut :: IO a -> IO (Either String a)
- simpleFallOut :: BreakFn
- mkBreakFn :: ObjectID -> BreakFn
- newFallOut :: IO (ObjectID, IO a -> IO (Either String a))
- isOurFallOut :: ObjectID -> Dyn -> Maybe String
- addGeneralFallOut :: Typeable a => IO (GeneralBreakFn a, GeneralCatchFn a)
- data GeneralBreakFn a = GeneralBreakFn (forall b. a -> b)
- data GeneralCatchFn a = GeneralCatchFn (forall c. IO c -> IO (Either a c))
- catchOurExceps :: IO a -> IO (Either String a)
- catchAllExceps :: IO a -> IO (Either String a)
- errorOurExceps :: IO a -> IO a
- ourExcepToMess :: Dyn -> Maybe String
- breakOtherExceps :: BreakFn -> IO a -> IO a
- showException2 :: Dyn -> String
- class EqIO v where
- class EqIO v => OrdIO v where
- newtype Full a = Full a
- uniqOrd :: Ord a => [a] -> [a]
- uniqOrdOrder :: Ord a => [a] -> [a]
- uniqOrdByKey :: Ord b => (a -> b) -> [a] -> [a]
- uniqOrdByKeyOrder :: Ord b => (a -> b) -> [a] -> [a]
- allSame :: (a -> Bool) -> [a] -> Maybe Bool
- allEq :: Eq a => [a] -> Bool
- findDuplicate :: Ord a => (b -> a) -> [b] -> Maybe b
- generalisedMerge :: Monad m => [a] -> [b] -> (a -> b -> Ordering) -> (Maybe a -> Maybe b -> m (Maybe a, Maybe c)) -> m ([a], [c])
Trimming spaces from Strings and putting them back again.
trimTrailing :: String -> StringSource
Remove trailing spaces (We try to avoid reconstructing the string, on the assumption that there aren't often spaces)
trimLeading :: String -> StringSource
Remove leading spaces
trimSpaces :: String -> StringSource
Remove trailing and leading spaces
padToLength :: Int -> String -> StringSource
Pad a string if necessary to the given length with leading spaces.
Miscellaneous functions
monadDot :: Monad m => (b -> m c) -> (a -> m b) -> a -> m cSource
The . operator lifted to monads. So like ., the arguments are given in the reverse order to that in which they should be executed.
simpleSplit :: (a -> Bool) -> [a] -> [[a]]Source
insertOrdLt :: Ord a => a -> [a] -> [a]Source
insertOrdGt :: Ord a => a -> [a] -> [a]Source
insertOrdAlternate :: (a -> a -> Ordering) -> a -> (a -> a) -> [a] -> [a]Source
insertOrdAlternate is similar to insertOrd except (1) it takes an Ordering argument; (2) if it finds an argument that matches, it applies the given function to generate a new element, rather than inserting another. The new generated element should be EQ to the old one.
readCheck :: Read a => String -> Maybe aSource
returns Just a if we can read a, and the rest is just spaces.
isPrefix :: Eq a => [a] -> [a] -> Maybe [a]Source
returns remainder if the first list is a prefix of the second one.
class HasCoMapIO option whereSource
class HasMapMonadic h whereSource
mapMonadic :: Monad m => (a -> m b) -> h a -> m (h b)Source
mapPartialM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b]Source
splitByChar :: Char -> String -> [String]Source
Miscellaneous string and list operations
unsplitByChar :: Char -> [String] -> StringSource
unsplitByChar0 :: Char -> [String] -> StringSource
splitToChar :: Char -> String -> Maybe (String, String)Source
We split at the first occurrence of the character, returning the string before and after.
splitToElem :: (a -> Bool) -> [a] -> Maybe ([a], [a])Source
splitToElemGeneral :: (a -> Bool) -> [a] -> Maybe ([a], a, [a])Source
deleteFirst :: (a -> Bool) -> [a] -> [a]Source
deleteFirstOpt :: (a -> Bool) -> [a] -> [a]Source
deleteAndFindFirst :: (a -> Bool) -> [a] -> (a, [a])Source
deleteAndFindFirstOpt :: (a -> Bool) -> [a] -> Maybe (a, [a])Source
divideList :: (a -> Either b c) -> [a] -> ([b], [c])Source
Folding on trees
treeFold :: (ancestorInfo -> state -> node -> (ancestorInfo, state, [node])) -> ancestorInfo -> state -> node -> stateSource
node is the tree's node type. state is folded through every node of the tree (and is the result). We search the tree in depth-first order, applying visitNode at each node to update the state. The ancestorInfo information comes from the ancestors of the node. EG if we are visiting node N1 which came from N2 the ancestorInfo given to visitNode for N1 will be that computed from visitNode for N2. For the root node, it will be initialAncestor
treeFoldM :: Monad m => (ancestorInfo -> state -> node -> m (ancestorInfo, state, [node])) -> ancestorInfo -> state -> node -> m stateSource
Like treeFold, but using monads.
Exception-driven error mechanism.
type BreakFn = forall other. String -> otherSource
A function indicating we want to escape from the current computation.
addFallOut :: (BreakFn -> IO a) -> IO (Either String a)Source
Intended use, EG addFallOut ( break -> do -- blah blah (normal IO a stuff) -- when (break condition) (break You can't do that there ere) -- more blah blah, not executed if there's an break -- return (value of type a) )
addFallOutWE :: (BreakFn -> IO a) -> IO (WithError a)Source
Like addFallOut, but returns a WithError object instead.
addGeneralFallOut :: Typeable a => IO (GeneralBreakFn a, GeneralCatchFn a)Source
data GeneralBreakFn a Source
GeneralBreakFn (forall b. a -> b) |
data GeneralCatchFn a Source
GeneralCatchFn (forall c. IO c -> IO (Either a c)) |
errorOurExceps :: IO a -> IO aSource
ourExcepToMess :: Dyn -> Maybe StringSource
breakOtherExceps :: BreakFn -> IO a -> IO aSource
showException2 :: Dyn -> StringSource
Other miscellaneous functions
indicates that an Ord or Eq instance really does need to take everything into account.
Full a |
uniqOrdOrder :: Ord a => [a] -> [a]Source
Like uniqOrd, except that we specify the output order of the list. The resulting list is that obtained by deleting all duplicate elements in the list, except the first, for example [1,2,3,2,1,4] will go to [1,2,3,4].
uniqOrdByKey :: Ord b => (a -> b) -> [a] -> [a]Source
Remove duplicate elements from a list where the key function is supplied.
uniqOrdByKeyOrder :: Ord b => (a -> b) -> [a] -> [a]Source
Remove duplicate elements from a list where the key function is supplied. The list order is preserved and of the duplicates, it is the first in the list which is not deleted.
allSame :: (a -> Bool) -> [a] -> Maybe BoolSource
Return Just True if all the elements give True, Just False if all False, Nothing otherwise (or list is empty).
findDuplicate :: Ord a => (b -> a) -> [b] -> Maybe bSource
If there are two elements of the list with the same (a), return one, otherwise Nothing.
:: Monad m | |
=> [a] | input list |
-> [b] | list to combine with input list |
-> (a -> b -> Ordering) | comparison function. a and b should be already sorted consistently with this comparison function, and it is assumed that each list is EQ to at most one of the other. |
-> (Maybe a -> Maybe b -> m (Maybe a, Maybe c)) | Merge function applied to each element of a and b, where we pair EQ elements together. |
-> m ([a], [c]) | Output of merge function concatenated. |
A merge function for combining an input list with some new data, where both are pre-sorted.