battleship

Safe HaskellSafe

Aux

Description

This trusted module defines several auxiliary functions.

Synopsis

Documentation

update :: [a] -> Int -> a -> [a]

update xs i y returns the list that's like xs except that its ith (counting from 0) element is y. It raises an exception if i isn't an index into xs.

strToInteger :: String -> Maybe Integer

strToInteger x returns Nothing, if x isn't a numeral; oherwise, it returns Just of the integer corresponding to x. Numerals are in base-10, and negative numerals have a leading "-".

mapInd :: (Int -> a -> b) -> [a] -> [b]

mapInd f [x_0, ..., x_{n - 1}] returns [f 0 x_0, ..., f (n - 1) x_{n - 1}].

tokens :: Eq a => (a -> Bool) -> [a] -> [[a]]

tokens f xs returns the unique list [ys_1, ..., ys_n] of nonempty sublists of xs such that there are nonempty lists zs_1, ... zs_{n - 1} such that

  • xs = ys_1 ++ zs_1 ++ ... ++ ys_{n - 1} ++ zs_{n - 1} ++ ys_n; and
  • all f zs_1 && ... && all f zs_{n - 1} == True.

strip :: String -> String

strip x removes leading and trailing whitespace from xs.

allButLast :: [a] -> [a]

allButLast xs returns all elements of xs except the final one. Raises an exception when xs is empty.