futhark-0.16.3: An optimising compiler for a functional, array-oriented language.

Futhark.Util

Description

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

# 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.

dropAt :: Int -> Int -> [a] -> [a] Source #

dropAt i n drops n elements starting at element i.

takeLast :: Int -> [a] -> [a] Source #

takeLast n l takes the last n elements of l.

dropLast :: Int -> [a] -> [a] Source #

dropLast n l drops the last n elements of l.

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.

maybeHead :: [a] -> Maybe a Source #

Return the first element of the list, if it exists.

splitFromEnd :: Int -> [a] -> ([a], [a]) Source #

Like splitAt, but from the end.

splitAt3 :: Int -> Int -> [a] -> ([a], [a], [a]) Source #

Like splitAt, but produces three lists.

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.

The Unix environment when the Futhark compiler started.

Is an environment variable set to 0 or 1? If 0, return False; if 1, True; otherwise the default value.

Are we running in a terminal capable of fancy commands and visualisation?

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.

Every non-directory file contained in a directory tree.

Round a single-precision floating point number correctly.

Round a single-precision floating point number upwards correctly.

Round a single-precision floating point number downwards correctly.

Round a double-precision floating point number correctly.

Round a double-precision floating point number upwards correctly.

Round a double-precision floating point number downwards correctly.

The system-level lgamma() function.

The system-level lgammaf() function.

The system-level tgamma() function.

The system-level tgammaf() function.

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.

Turn a POSIX filepath into a filepath for the native system.

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.

As the user typed it.

Encoded form.

Z-encode a string using a slightly simplified variant of GHC Z-encoding. The encoded string is a valid identifier in most programming languages.