Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
Non-Futhark-specific utilities. If you find yourself writing general functions on generic data structures, consider putting them here.
Sometimes it is also preferable to copy a small function rather than introducing a large dependency. In this case, make sure to note where you got it from (and make sure that the license is compatible).
Synopsis
- nubOrd :: Ord a => [a] -> [a]
- mapAccumLM :: Monad m => (acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y])
- maxinum :: (Num a, Ord a, Foldable f) => f a -> a
- chunk :: Int -> [a] -> [[a]]
- chunks :: [Int] -> [a] -> [[a]]
- dropAt :: Int -> Int -> [a] -> [a]
- takeLast :: Int -> [a] -> [a]
- dropLast :: Int -> [a] -> [a]
- mapEither :: (a -> Either b c) -> [a] -> ([b], [c])
- maybeNth :: Integral int => int -> [a] -> Maybe a
- maybeHead :: [a] -> Maybe a
- splitFromEnd :: Int -> [a] -> ([a], [a])
- splitAt3 :: Int -> Int -> [a] -> ([a], [a], [a])
- focusNth :: Integral int => int -> [a] -> Maybe ([a], a, [a])
- hashIntText :: Int -> Text
- unixEnvironment :: [(String, String)]
- isEnvVarAtLeast :: String -> Int -> Bool
- fancyTerminal :: Bool
- runProgramWithExitCode :: FilePath -> [String] -> ByteString -> IO (Either IOException (ExitCode, String, String))
- directoryContents :: FilePath -> IO [FilePath]
- roundFloat :: Float -> Float
- ceilFloat :: Float -> Float
- floorFloat :: Float -> Float
- roundDouble :: Double -> Double
- ceilDouble :: Double -> Double
- floorDouble :: Double -> Double
- lgamma :: Double -> Double
- lgammaf :: Float -> Float
- tgamma :: Double -> Double
- tgammaf :: Float -> Float
- fromPOSIX :: FilePath -> FilePath
- toPOSIX :: FilePath -> FilePath
- trim :: String -> String
- pmapIO :: Maybe Int -> (a -> IO b) -> [a] -> IO [b]
- readFileSafely :: FilePath -> IO (Maybe (Either String Text))
- type UserString = String
- type EncodedString = String
- zEncodeString :: UserString -> EncodedString
- atMostChars :: Int -> String -> String
Documentation
mapAccumLM :: Monad m => (acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y]) Source #
Like mapAccumL
, but monadic.
maxinum :: (Num a, Ord a, Foldable f) => f a -> a Source #
Like maximum
, but returns zero for an empty list.
chunk :: Int -> [a] -> [[a]] Source #
chunk n a
splits a
into n
-size-chunks. If the length of
a
is not divisible by n
, the last chunk will have fewer than
n
elements (but it will never be empty).
chunks :: [Int] -> [a] -> [[a]] Source #
chunks ns a
splits a
into chunks determined by the elements
of ns
. It must hold that sum ns == length a
, or the resulting
list may contain too few chunks, or not all elements of a
.
mapEither :: (a -> Either b c) -> [a] -> ([b], [c]) Source #
A combination of map
and partitionEithers
.
maybeNth :: Integral int => int -> [a] -> Maybe a Source #
Return the list element at the given index, if the index is valid.
splitFromEnd :: Int -> [a] -> ([a], [a]) Source #
Like splitAt
, but from the end.
focusNth :: Integral int => int -> [a] -> Maybe ([a], a, [a]) Source #
Return the list element at the given index, if the index is valid, along with the elements before and after.
hashIntText :: Int -> Text Source #
Convert the given integer (implied to be a hash digest) to a hexadecimal non-negative number.
unixEnvironment :: [(String, String)] Source #
The Unix environment when the Futhark compiler started.
isEnvVarAtLeast :: String -> Int -> Bool Source #
True if the environment variable, viewed as an integer, has at least this numeric value. Returns False if variable is unset or not numeric.
fancyTerminal :: Bool Source #
Are we running in a terminal capable of fancy commands and visualisation?
runProgramWithExitCode :: FilePath -> [String] -> ByteString -> IO (Either IOException (ExitCode, String, String)) Source #
Like readProcessWithExitCode
, but also wraps exceptions when
the indicated binary cannot be launched, or some other exception is
thrown. Also does shenanigans to handle improperly encoded outputs.
directoryContents :: FilePath -> IO [FilePath] Source #
Every non-directory file contained in a directory tree.
roundFloat :: Float -> Float Source #
Round a single-precision floating point number correctly.
ceilFloat :: Float -> Float Source #
Round a single-precision floating point number upwards correctly.
floorFloat :: Float -> Float Source #
Round a single-precision floating point number downwards correctly.
roundDouble :: Double -> Double Source #
Round a double-precision floating point number correctly.
ceilDouble :: Double -> Double Source #
Round a double-precision floating point number upwards correctly.
floorDouble :: Double -> Double Source #
Round a double-precision floating point number downwards correctly.
fromPOSIX :: FilePath -> FilePath Source #
Some bad operating systems do not use forward slash as directory separator - this is where we convert Futhark includes (which always use forward slash) to native paths.
toPOSIX :: FilePath -> FilePath Source #
Turn a POSIX filepath into a filepath for the native system.
trim :: String -> String Source #
Remove leading and trailing whitespace from a string. Not an efficient implementation!
pmapIO :: Maybe Int -> (a -> IO b) -> [a] -> IO [b] Source #
Run various IO
actions concurrently, possibly with a bound on
the number of threads. The list must be finite. The ordering of
the result list is not deterministic - add your own sorting if
needed. If any of the actions throw an exception, then that
exception is propagated to this function.
type UserString = String Source #
As the user typed it.
type EncodedString = String Source #
Encoded form.
zEncodeString :: UserString -> EncodedString Source #
Z-encode a string using a slightly simplified variant of GHC Z-encoding. The encoded string is a valid identifier in most programming languages.