Hoogle Search
Within LTS Haskell 24.36 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
forceSwapTMVar :: TMVar a -> a -> STM (Maybe a)stm-extras Control.Concurrent.STM.TMVar.Extras Non-blocking swap of TMVar irreguardless if it previously contained a value or not. Returns what was in the TMVar (if exists)
formatted :: String -> Formatted a -> String -> Formatted atable-layout Text.Layout.Table.Cell.Formatted Create a formatted value with formatting directives that are applied to the whole value. The actual formatting has to be done by the backend.
fork :: Unexceptional m => UIO () -> m ThreadIdunexceptionalio-trans UnexceptionalIO.Trans Mirrors forkIO, but re-throws errors to the parent thread
- Ignores manual thread kills, since those are on purpose.
- Re-throws async exceptions (SomeAsyncException) as is.
- Re-throws ExitCode as is in an attempt to exit with the requested code.
- Wraps synchronous PseudoException in async ChildThreadError.
forkFinally :: Unexceptional m => UIO a -> (Either PseudoException a -> UIO ()) -> m ThreadIdunexceptionalio-trans UnexceptionalIO.Trans Mirrors forkFinally, but since the body is UIO, the thread must terminate successfully or because of PseudoException
forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b)verset Verset forM is mapM with its arguments flipped. For a version that ignores the results see forM_.
forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m ()verset Verset forM_ is mapM_ with its arguments flipped. For a version that doesn't ignore the results see forM. forM_ is just like for_, but specialised to monadic actions.
for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()verset Verset for_ is traverse_ with its arguments flipped. For a version that doesn't ignore the results see for. This is forM_ generalised to Applicative actions. for_ is just like forM_, but generalised to Applicative actions.
Examples
Basic usage:>>> for_ [1..4] print 1 2 3 4
forever :: Applicative f => f a -> f bverset Verset Repeat an action indefinitely.
Examples
A common use of forever is to process input from network sockets, Handles, and channels (e.g. MVar and Chan). For example, here is how we might implement an echo server, using forever both to listen for client connections on a network socket and to echo client input on client connection handles:echoServer :: Socket -> IO () echoServer socket = forever $ do client <- accept socket forkFinally (echo client) (\_ -> hClose client) where echo :: Handle -> IO () echo client = forever $ hGetLine client >>= hPutStrLn client
Note that "forever" isn't necessarily non-terminating. If the action is in a MonadPlus and short-circuits after some number of iterations. then forever actually returns mzero, effectively short-circuiting its caller.forkFinally :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadIdverset Verset Fork a thread and call the supplied function when the thread is about to terminate, with an exception or a returned value. The function is called with asynchronous exceptions masked.
forkFinally action and_then = mask $ \restore -> forkIO $ try (restore action) >>= and_then
This function is useful for informing the parent when a child terminates, for example.forkIO :: IO () -> IO ThreadIdverset Verset Creates a new thread to run the IO computation passed as the first argument, and returns the ThreadId of the newly created thread. The new thread will be a lightweight, unbound thread. Foreign calls made by this thread are not guaranteed to be made by any particular OS thread; if you need foreign calls to be made by a particular OS thread, then use forkOS instead. The new thread inherits the masked state of the parent (see mask). The newly created thread has an exception handler that discards the exceptions BlockedIndefinitelyOnMVar, BlockedIndefinitelyOnSTM, and ThreadKilled, and passes all other exceptions to the uncaught exception handler. WARNING: Exceptions in the new thread will not be rethrown in the thread that created it. This means that you might be completely unaware of the problem if/when this happens. You may want to use the async library instead.