Hoogle Search
Within LTS Haskell 24.50 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
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.
forgetWSGroup :: WSGroupId -> X ()xmonad-contrib XMonad.Actions.DynamicWorkspaceGroups Delete the named workspace group from the list of workspace groups. Note that this has no effect on the workspaces involved; it simply forgets the given name.
foreground :: MessageConfig -> [Char]xmonad-contrib XMonad.Actions.LinkWorkspaces No documentation available.
for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()xmonad-contrib XMonad.Prelude 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
for_ :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m b) -> m ()yjtools Control.Monad.Tools No documentation available.
-
base Data.Char Cf: Other, Format
-
A collection of data types, classes, and functions for interfacing with another programming language.
-
The ForeignPtr type and operations. This module is part of the Foreign Function Interface (FFI) and will usually be imported via the Foreign module. For non-portable support of Haskell finalizers, see the Foreign.Concurrent module.