Hoogle Search

Within LTS Haskell 24.34 (ghc-9.10.3)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()

    protolude Protolude

    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
    

  2. force :: NFData a => a -> a

    protolude Protolude

    a variant of deepseq that is useful in some circumstances:

    force x = x `deepseq` x
    
    force x fully evaluates x, and then returns it. Note that force x only performs evaluation when the value of force x itself is demanded, so essentially it turns shallow evaluation into deep evaluation. force can be conveniently used in combination with ViewPatterns:
    {-# LANGUAGE BangPatterns, ViewPatterns #-}
    import Control.DeepSeq
    
    someFun :: ComplexData -> SomeResult
    someFun (force -> !arg) = {- 'arg' will be fully evaluated -}
    
    Another useful application is to combine force with evaluate in order to force deep evaluation relative to other IO operations:
    import Control.Exception (evaluate)
    import Control.DeepSeq
    
    main = do
    result <- evaluate $ force $ pureComputation
    {- 'result' will be fully evaluated at this point -}
    return ()
    
    Finally, here's an exception safe variant of the readFile' example:
    readFile' :: FilePath -> IO String
    readFile' fn = bracket (openFile fn ReadMode) hClose $ \h ->
    evaluate . force =<< hGetContents h
    

  3. forkFinally :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId

    protolude Protolude

    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.

  4. forkIO :: IO () -> IO ThreadId

    protolude Protolude

    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.

  5. forkIOWithUnmask :: ((forall a . () => IO a -> IO a) -> IO ()) -> IO ThreadId

    protolude Protolude

    Like forkIO, but the child thread is passed a function that can be used to unmask asynchronous exceptions. This function is typically used in the following way

    ... mask_ $ forkIOWithUnmask $ \unmask ->
    catch (unmask ...) handler
    
    so that the exception handler in the child thread is established with asynchronous exceptions masked, meanwhile the main body of the child thread is executed in the unmasked state. Note that the unmask function passed to the child thread should only be used in that thread; the behaviour is undefined if it is invoked in a different thread.

  6. forkOS :: IO () -> IO ThreadId

    protolude Protolude

    Like forkIO, this sparks off a new thread to run the IO computation passed as the first argument, and returns the ThreadId of the newly created thread. However, forkOS creates a bound thread, which is necessary if you need to call foreign (non-Haskell) libraries that make use of thread-local state, such as OpenGL (see Control.Concurrent#boundthreads). Using forkOS instead of forkIO makes no difference at all to the scheduling behaviour of the Haskell runtime system. It is a common misconception that you need to use forkOS instead of forkIO to avoid blocking all the Haskell threads when making a foreign call; this isn't the case. To allow foreign calls to be made without blocking all the Haskell threads (with GHC), it is only necessary to use the -threaded option when linking your program, and to make sure the foreign import is not marked unsafe.

  7. forkOSWithUnmask :: ((forall a . () => IO a -> IO a) -> IO ()) -> IO ThreadId

    protolude Protolude

    Like forkIOWithUnmask, but the child thread is a bound thread, as with forkOS.

  8. forkOn :: Int -> IO () -> IO ThreadId

    protolude Protolude

    Like forkIO, but lets you specify on which capability the thread should run. Unlike a forkIO thread, a thread created by forkOn will stay on the same capability for its entire lifetime (forkIO threads can migrate between capabilities according to the scheduling policy). forkOn is useful for overriding the scheduling policy when you know in advance how best to distribute the threads. The Int argument specifies a capability number (see getNumCapabilities). Typically capabilities correspond to physical processors, but the exact behaviour is implementation-dependent. The value passed to forkOn is interpreted modulo the total number of capabilities as returned by getNumCapabilities. GHC note: the number of capabilities is specified by the +RTS -N option when the program is started. Capabilities can be fixed to actual processor cores with +RTS -qa if the underlying operating system supports that, although in practice this is usually unnecessary (and may actually degrade performance in some cases - experimentation is recommended).

  9. forkOnWithUnmask :: Int -> ((forall a . () => IO a -> IO a) -> IO ()) -> IO ThreadId

    protolude Protolude

    Like forkIOWithUnmask, but the child thread is pinned to the given CPU, as with forkOn.

  10. foreach :: Functor f => f a -> (a -> b) -> f b

    protolude Protolude.Functor

    No documentation available.

Page 63 of many | Previous | Next