cat +base

catch :: IO a -> (IOError -> IO a) -> IO a
base Prelude, base System.IO.Error
The catch function establishes a handler that receives any IOError raised in the action protected by catch. An IOError is caught by the most recent handler established by catch. These handlers are not selective: all IOErrors are caught. Exception propagation must be explicitly provided in a handler by re-raising any unwanted exceptions. For example, in > f = catch g (\e -> if IO.isEOFError e then return [] else ioError e) the function f returns [] when an end-of-file exception (cf. isEOFError) occurs in g; otherwise, the exception is propagated to the next outer handler. When an exception propagates outside the main program, the Haskell system prints the associated IOError value and exits the program. Non-I/O exceptions are not caught by this variant; to catch all exceptions, use Control.Exception.catch from Control.Exception.
catch :: IO a -> (Exception -> IO a) -> IO a
base Control.OldException
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
catch :: Exception e => IO a -> (e -> IO a) -> IO a
base Control.Exception.Base, base Control.Exception
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
catchDyn :: Typeable exception => IO a -> (exception -> IO a) -> IO a
base Control.OldException
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.
catches :: IO a -> [Handler a] -> IO a
base Control.Exception
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)]
catchJust :: (Exception -> Maybe b) -> IO a -> (b -> IO a) -> IO a
base Control.OldException
The function catchJust is like catch, but it takes an extra argument which is an exception predicate, a function which selects which type of exceptions we're interested in. There are some predefined exception predicates for useful subsets of exceptions: ioErrors, arithExceptions, and so on. For example, to catch just calls to the error function, we could use > result <- catchJust errorCalls thing_to_try handler Any other exceptions which are not matched by the predicate are re-raised, and may be caught by an enclosing catch or catchJust.
catchJust :: Exception e => (e -> Maybe b) -> IO a -> (b -> IO a) -> IO a
base Control.Exception.Base, base Control.Exception
The function catchJust is like catch, but it takes an extra argument which is an exception predicate, a function which selects which type of exceptions we're interested in. > catchJust (\e -> if isDoesNotExistErrorType (ioeGetErrorType e) then Just () else Nothing) > (readFile f) > (\_ -> do hPutStrLn stderr ("No such file: " ++ show f) > return "") Any other exceptions which are not matched by the predicate are re-raised, and may be caught by an enclosing catch, catchJust, etc.
catMaybes :: [Maybe a] -> [a]
base Data.Maybe
The catMaybes function takes a list of Maybes and returns a list of all the Just values.
catchSTM :: Exception e => STM a -> (e -> STM a) -> STM a
base GHC.Conc.Sync, base GHC.Conc
Exception handling within STM actions.
class Category cat
base Control.Category
A class for categories. id and (.) must form a monoid.
module Control.Category
base Control.Category
concat :: [[a]] -> [a]
base Prelude, base Data.List
Concatenate a list of lists.
concatMap :: (a -> [b]) -> [a] -> [b]
base Prelude, base Data.List
Map a function over a list and concatenate the results.
replicate :: Int -> a -> [a]
base Prelude, base Data.List
replicate n x is a list of length n with x the value of every element. It is an instance of the more general Data.List.genericReplicate, in which n may be of any integral type.
truncate :: (RealFrac a, Integral b) => a -> b
base Prelude
class Functor f => Applicative f
base Control.Applicative
A functor with application. Instances should satisfy the following laws: * identity pure id <*> v = v * composition pure (.) <*> u <*> v <*> w = u <*> (v <*> w) * homomorphism pure f <*> pure x = pure (f x) * interchange u <*> pure y = pure ($ y) <*> u * ignore left value u *> v = pure (const id) <*> u <*> v * ignore right value u <* v = pure const <*> u <*> v The Functor instance should satisfy > fmap f x = pure f <*> x If f is also a Monad, define pure = return and (<*>) = ap. Minimal complete definition: pure and <*>.
concat :: Foldable t => t [a] -> [a]
base Data.Foldable
The concatenation of all the elements of a container of lists.
concatMap :: Foldable t => (a -> [b]) -> t a -> [b]
base Data.Foldable
Map a function over all the elements of a container and concatenate the resulting lists.
module Control.Applicative
base Control.Applicative
This module describes a structure intermediate between a functor and a monad: it provides pure expressions and sequencing, but no binding. (Technically, a strong lax monoidal functor.) For more details, see Applicative Programming with Effects, by Conor McBride and Ross Paterson, online at http://www.soi.city.ac.uk/~ross/papers/Applicative.html. This interface was introduced for parsers by Niklas Röjemo, because it admits more sharing than the monadic interface. The names here are mostly based on recent parsing work by Doaitse Swierstra. This class is also useful with instances of the Data.Traversable.Traversable class.
data GeneralCategory
base Data.Char
Unicode General Categories (column 2 of the UnicodeData table) in the order they are listed in the Unicode standard.

Show more results