ContentsIndex
GenUtil
Contents
Functions
Error reporting
Simple deconstruction
System routines
Random routines
Monad routines
Text Routines
Quoting
Random
Classes
Description
This is a collection of random useful utility functions written in pure Haskell 98. In general, it trys to conform to the naming scheme put forth the haskell prelude and fill in the obvious omissions, as well as provide useful routines in general. To ensure maximum portability, no instances are exported so it may be added to any project without conflicts.
Synopsis
putErr :: String -> IO ()
putErrLn :: String -> IO ()
putErrDie :: String -> IO a
fromLeft :: Either a b -> a
fromRight :: Either a b -> b
fsts :: [(a, b)] -> [a]
snds :: [(a, b)] -> [b]
splitEither :: [Either a b] -> ([a], [b])
rights :: [Either a b] -> [b]
lefts :: [Either a b] -> [a]
exitSuccess :: IO a
exitFailure
epoch :: ClockTime
lookupEnv :: MonadPlus m => String -> IO (m String)
endOfTime :: ClockTime
repMaybe :: (a -> Maybe a) -> a -> a
liftT2 :: (a -> b, c -> d) -> (a, c) -> (b, d)
snub :: Ord a => [a] -> [a]
snubFst :: Ord a => [(a, b)] -> [(a, b)]
sortFst :: Ord a => [(a, b)] -> [(a, b)]
groupFst :: Eq a => [(a, b)] -> [[(a, b)]]
foldl' :: (a -> b -> a) -> a -> [b] -> a
fmapLeft :: Functor f => (a -> c) -> f (Either a b) -> f (Either c b)
fmapRight :: Functor f => (b -> c) -> f (Either a b) -> f (Either a c)
isDisjoint :: Eq a => [a] -> [a] -> Bool
isConjoint :: Eq a => [a] -> [a] -> Bool
repeatM :: Monad m => m a -> m [a]
repeatM_ :: Monad m => m a -> m ()
replicateM :: Monad m => Int -> m a -> m [a]
replicateM_ :: Monad m => Int -> m a -> m ()
maybeToMonad :: Monad m => Maybe a -> m a
toMonadM :: Monad m => m (Maybe a) -> m a
ioM :: Monad m => IO a -> IO (m a)
ioMp :: MonadPlus m => IO a -> IO (m a)
foldlM :: Monad m => (a -> b -> m a) -> a -> [b] -> m a
foldlM_ :: Monad m => (a -> b -> m a) -> a -> [b] -> m ()
foldl1M :: Monad m => (a -> a -> m a) -> [a] -> m a
foldl1M_ :: Monad m => (a -> a -> m a) -> [a] -> m ()
shellQuote :: [String] -> String
simpleQuote :: [String] -> String
simpleUnquote :: String -> [String]
concatInter :: String -> [String] -> String
powerSet :: [a] -> [[a]]
indentLines :: Int -> String -> String
buildTableLL :: [(String, String)] -> [String]
buildTableRL :: [(String, String)] -> [String]
randomPermute :: StdGen -> [a] -> [a]
randomPermuteIO :: [a] -> IO [a]
trimBlankLines :: String -> String
paragraph :: Int -> String -> String
paragraphBreak :: Int -> String -> String
chunk :: Int -> [a] -> [[a]]
chunkText :: Int -> String -> String
fromEither :: Either a a -> a
tr :: String -> String -> String -> String
readHex :: Monad m => String -> m Int
overlaps :: Ord a => (a, a) -> (a, a) -> Bool
showDuration :: Integral a => a -> String
readM :: (Monad m, Read a) => String -> m a
readsM :: (Monad m, Read a) => String -> m (a, String)
class Monad m => UniqueProducer m where
newUniq :: m Int
Functions
Error reporting
putErr :: String -> IO ()
write string to standard error
putErrLn :: String -> IO ()
write string and newline to standard error
putErrDie :: String -> IO a
write string and newline to standard error, then exit program with failure.
Simple deconstruction
fromLeft :: Either a b -> a
fromRight :: Either a b -> b
fsts :: [(a, b)] -> [a]
take the fst of every element of a list
snds :: [(a, b)] -> [b]
take the snd of every element of a list
splitEither :: [Either a b] -> ([a], [b])
partition a list of eithers.
rights :: [Either a b] -> [b]
take just the rights
lefts :: [Either a b] -> [a]
take just the lefts
System routines
exitSuccess :: IO a
exit program successfully. exitFailure is also exported from System.
exitFailure
epoch :: ClockTime
the standard unix epoch
lookupEnv :: MonadPlus m => String -> IO (m String)
looks up an enviornment variable and returns it in a MonadPlus rather than raising an exception if the variable is not set.
endOfTime :: ClockTime
an arbitrary time in the future
Random routines
repMaybe :: (a -> Maybe a) -> a -> a
recursivly apply function to value until it returns Nothing
liftT2 :: (a -> b, c -> d) -> (a, c) -> (b, d)
apply functions to values inside a tupele. liftT3 and liftT4 also exist.
snub :: Ord a => [a] -> [a]
sorted nub of list, much more efficient than nub, but doesnt preserve ordering.
snubFst :: Ord a => [(a, b)] -> [(a, b)]
sorted nub of list of tuples, based solely on the first element of each tuple.
sortFst :: Ord a => [(a, b)] -> [(a, b)]
sort list of tuples, based on first element of each tuple.
groupFst :: Eq a => [(a, b)] -> [[(a, b)]]
group list of tuples, based only on equality of the first element of each tuple.
foldl' :: (a -> b -> a) -> a -> [b] -> a
strict version of foldl
fmapLeft :: Functor f => (a -> c) -> f (Either a b) -> f (Either c b)
fmapRight :: Functor f => (b -> c) -> f (Either a b) -> f (Either a c)
isDisjoint :: Eq a => [a] -> [a] -> Bool
set operations on lists. (slow!)
isConjoint :: Eq a => [a] -> [a] -> Bool
Monad routines
repeatM :: Monad m => m a -> m [a]
repeatM_ :: Monad m => m a -> m ()
replicateM :: Monad m => Int -> m a -> m [a]
replicateM_ :: Monad m => Int -> m a -> m ()
maybeToMonad :: Monad m => Maybe a -> m a
convert a maybe to an arbitrary failable monad
toMonadM :: Monad m => m (Maybe a) -> m a
ioM :: Monad m => IO a -> IO (m a)
ioMp :: MonadPlus m => IO a -> IO (m a)
foldlM :: Monad m => (a -> b -> m a) -> a -> [b] -> m a
foldlM_ :: Monad m => (a -> b -> m a) -> a -> [b] -> m ()
foldl1M :: Monad m => (a -> a -> m a) -> [a] -> m a
foldl1M_ :: Monad m => (a -> a -> m a) -> [a] -> m ()
Text Routines
Quoting
shellQuote :: [String] -> String
quote a set of strings as would be appropriate to pass them as arguments to a sh style shell
simpleQuote :: [String] -> String
quote strings rc style. single quotes protect any characters between them, to get an actual single quote double it up. Inverse of simpleUnquote
simpleUnquote :: String -> [String]
inverse of simpleQuote
Random
concatInter :: String -> [String] -> String
concat composed with intersperse.
powerSet :: [a] -> [[a]]
compute the power set of a list
indentLines :: Int -> String -> String
place spaces before each line in string.
buildTableLL :: [(String, String)] -> [String]
buildTableRL :: [(String, String)] -> [String]
randomPermute :: StdGen -> [a] -> [a]
randomly permute a list given a RNG
randomPermuteIO :: [a] -> IO [a]
randomly permute a list, using the standard random number generator.
trimBlankLines :: String -> String
trim blank lines at beginning and end of string
paragraph :: Int -> String -> String
reformat a string to not be wider than a given width, breaking it up between words.
paragraphBreak :: Int -> String -> String
chunk :: Int -> [a] -> [[a]]
chunkText :: Int -> String -> String
fromEither :: Either a a -> a
tr :: String -> String -> String -> String
readHex :: Monad m => String -> m Int
overlaps :: Ord a => (a, a) -> (a, a) -> Bool
determine if two closed intervals overlap at all.
showDuration :: Integral a => a -> String
translate a number of seconds to a string representing the duration expressed.
readM :: (Monad m, Read a) => String -> m a
readsM :: (Monad m, Read a) => String -> m (a, String)
Classes
class Monad m => UniqueProducer m where
class for monads which can generate unique values.
Methods
newUniq :: m Int
produce a new unique value
Instances
Produced by Haddock version 0.6