Alternative f => [f a] -> f a +base
The sum of a collection of actions, generalizing concat.
This generalizes the list-based concat function.
Combines all parsers in the specified list.
Combines all parsers in the specified list.
Concatenate a list of lists.
The sum of a collection of actions, generalizing concat.
intercalate xs xss is equivalent to (concat (intersperse xs xss)). It inserts the list xs in between the lists in xss and concatenates the result.
Evaluate each action in the sequence from left to right, and ignore the results.
The transpose function transposes the rows and columns of its argument. For example,
> transpose [[1,2,3],[4,5,6]] == [[1,4],[2,5],[3,6]]
The concatenation of all the elements of a container of lists.
One or none.
Note: this function is deprecated, please use mask instead.
Applying block to a computation will execute that computation with asynchronous exceptions blocked. That is, any thread which attempts to raise an exception in the current thread with Control.Exception.throwTo will be blocked until asynchronous exceptions are unblocked again. There's no need to worry about re-enabling asynchronous exceptions; that is done automatically on exiting the scope of block.
Threads created by Control.Concurrent.forkIO inherit the blocked state from the parent; that is, to start a thread in blocked mode, use block $ forkIO .... This is particularly useful if you need to establish an exception handler in the forked thread before any asynchronous exceptions are received.
Like mask, but does not pass a restore action to the argument.
Run the IO computation passed as the first argument. If the calling thread is not bound, a bound thread is created temporarily. runInBoundThread doesn't finish until the IO computation finishes.
You can wrap a series of foreign function calls that rely on thread-local state with runInBoundThread so that you can use them without knowing whether the current thread is bound.
Run the IO computation passed as the first argument. If the calling thread is bound, an unbound thread is created temporarily using forkIO. runInBoundThread doesn't finish until the IO computation finishes.
Use this function only in the rare case that you have actually observed a performance loss due to the use of bound threads. A program that doesn't need it's main thread to be bound and makes heavy use of concurrency (e.g. a web server), might want to wrap it's main action in runInUnboundThread.
Note that exceptions which are thrown to the current thread are thrown in turn to the thread that is executing the given computation. This ensures there's always a way of killing the forked thread.
Note: this function is deprecated, please use mask instead.
To re-enable asynchronous exceptions inside the scope of block, unblock can be used. It scopes in exactly the same way, so on exit from unblock asynchronous exception delivery will be disabled again.
unsafeInterleaveIO allows IO computation to be deferred lazily. When passed a value of type IO a, the IO will only be performed when the value of the a is demanded. This is used to implement lazy file reading, see System.IO.hGetContents.
(parens p) parses "P", "(P0)", "((P0))", etc, p parses "P" in the current precedence context and parses "P0" in precedence context zero
Resets the precedence context to zero.
Increases the precedence context by one.
cycle ties a finite list into a circular one, or equivalently, the infinite repetition of the original list. It is the identity on infinite lists.
Return all the elements of a list except the last one. The list must be non-empty.
reverse xs returns the elements of xs in reverse order. xs must be finite.
Extract the elements after the head of a list, which must be non-empty.
unlines is an inverse operation to lines. It joins lines, after appending a terminating newline to each.
unwords is an inverse operation to words. It joins words with separating spaces.
The join function is the conventional monad join operator. It is used to remove one level of monadic structure, projecting its bound argument into the outer level.
Direct MonadPlus equivalent of filter filter = (mfilter:: (a -> Bool) -> [a] -> [a] applicable to any MonadPlus, for example mfilter odd (Just 1) == Just 1 mfilter odd (Just 2) == Nothing
Evaluate each action in the structure from left to right, and ignore the results.
Evaluate each monadic action in the structure from left to right, and ignore the results.
Evaluate each action in the sequence from left to right, and collect the results.
A version of catch with the arguments swapped around; useful in situations
> do handle (\NonTermination -> exitWith (ExitFailure 1)) $
> ...
A version of catch with the arguments swapped around; useful in situations
> do handle (\e -> exitWith (ExitFailure 1)) $
> ...
Catch dynamic exceptions of the required type. All other exceptions are re-thrown, including dynamic exceptions of the wrong type.
When using dynamic exceptions it is advisable to define a new datatype to use for your exception type, to avoid possible clashes with dynamic exceptions used in other libraries.
This is the simplest of the exception-catching functions. It takes a single argument, runs it, and if an exception is raised the "handler" is executed, with the value of the exception passed as an argument. Otherwise, the result is returned as normal. For example:
> catch (readFile f)
> (\e -> do let err = show (e :: IOException)
> hPutStr stderr ("Warning: Couldn't open " ++ f ++ ": " ++ err)
> return "")
Note that we have to give a type signature to e, or the program will not typecheck as the type is ambiguous. While it is possible to catch exceptions of any type, see the previous section "Catching all exceptions" for an explanation of the problems with doing so.
For catching exceptions in pure (non-IO) expressions, see the function evaluate.
Note that due to Haskell's unspecified evaluation order, an expression may throw one of several possible exceptions: consider the expression (error "urk") + (1 `div` 0). Does the expression throw ErrorCall "urk", or DivideByZero?
The answer is "it might throw either"; the choice is non-deterministic. If you are catching any type of exception then you might catch either. If you are calling catch with type IO Int -> (ArithException -> IO Int) -> IO Int then the handler may get run with DivideByZero as an argument, or an ErrorCall "urk" exception may be propogated further up. If you call it again, you might get a the opposite behaviour. This is ok, because catch is an IO computation.
Note that the Prelude also exports a function called Prelude.catch with a similar type to Control.Exception.catch, except that the Prelude version only catches the IO and user families of exceptions (as required by Haskell 98).
We recommend either hiding the Prelude version of Prelude.catch when importing Control.Exception:
> import Prelude hiding (catch)
or importing Control.Exception qualified, to avoid name-clashes:
> import qualified Control.Exception as C
and then using C.catch
This is the simplest of the exception-catching functions. It takes a single argument, runs it, and if an exception is raised the "handler" is executed, with the value of the exception passed as an argument. Otherwise, the result is returned as normal. For example:
> catch (openFile f ReadMode)
> (\e -> hPutStr stderr ("Couldn't open "++f++": " ++ show e))
For catching exceptions in pure (non-IO) expressions, see the function evaluate.
Note that due to Haskell's unspecified evaluation order, an expression may return one of several possible exceptions: consider the expression error "urk" + 1 `div` 0. Does catch execute the handler passing ErrorCall "urk", or ArithError DivideByZero?
The answer is "either": catch makes a non-deterministic choice about which exception to catch. If you call it again, you might get a different exception back. This is ok, because catch is an IO computation.
Note that catch catches all types of exceptions, and is generally used for "cleaning up" before passing on the exception using throwIO. It is not good practice to discard the exception and continue, without first checking the type of the exception (it might be a ThreadKilled, for example). In this case it is usually better to use catchJust and select the kinds of exceptions to catch.
Also note that the Prelude also exports a function called Prelude.catch with a similar type to catch, except that the Prelude version only catches the IO and user families of exceptions (as required by Haskell 98).
We recommend either hiding the Prelude version of Prelude.catch when importing Control.OldException:
> import Prelude hiding (catch)
or importing Control.OldException qualified, to avoid name-clashes:
> import qualified Control.OldException as C
and then using C.catch
Sometimes you want to catch two different sorts of exception. You could do something like
> f = expr `catch` \ (ex :: ArithException) -> handleArith ex
> `catch` \ (ex :: IOException) -> handleIO ex
However, there are a couple of problems with this approach. The first is that having two exception handlers is inefficient. However, the more serious issue is that the second exception handler will catch exceptions in the first, e.g. in the example above, if handleArith throws an IOException then the second exception handler will catch it.
Instead, we provide a function catches, which would be used thus:
> f = expr `catches` [Handler (\ (ex :: ArithException) -> handleArith ex),
> Handler (\ (ex :: IOException) -> handleIO ex)]
A specialised variant of bracket with just a computation to run afterward.
Like finally, but only performs the final action if there was an exception raised by the computation.
Given an arbitrary address and an alignment constraint, alignPtr yields the next higher address that fulfills the alignment constraint. An alignment constraint x is fulfilled by any address divisible by x. This operation is idempotent.
option x p will either parse p or return x without consuming any input.
Like chainl, but parses one or more occurrences of p.
Like chainr, but parses one or more occurrences of p.
Symmetric choice.
Local, exclusive, left-biased choice: If left parser locally produces any result at all, then right parser is not used.
Symmetric choice.
Local, exclusive, left-biased choice: If left parser locally produces any result at all, then right parser is not used.
Exception handling within STM actions.
Compose two alternative STM actions (GHC only). If the first action completes without retrying then it forms the result of the orElse. Otherwise, if the first action retries, then the second action is tried in its place. If both actions retry then the orElse as a whole retries.
A list producer that can be fused with foldr. This function is merely
> augment g xs = g (:) xs
but GHC's simplifier will transform an expression of the form foldr k z (augment g xs), which may arise after inlining, to g k (foldr k z xs), which avoids producing an intermediate list.
The sortWith function sorts a list of elements using the user supplied function to project something out of each element
Show more results