Hoogle Search

Within LTS Haskell 24.40 (ghc-9.10.3)

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

  1. hWaitForInput :: Handle -> Int -> IO Bool

    base GHC.IO.Handle

    Computation hWaitForInput hdl t waits until input is available on handle hdl. It returns True as soon as input is available on hdl, or False if no input is available within t milliseconds. Note that hWaitForInput waits until one or more full characters are available, which means that it needs to do decoding, and hence may fail with a decoding error. If t is less than zero, then hWaitForInput waits indefinitely. This operation may fail with:

    • isEOFError if the end of file has been reached.
    • a decoding error, if the input begins with an invalid byte sequence in this Handle's encoding.
    NOTE for GHC users: unless you use the -threaded flag, hWaitForInput hdl t where t >= 0 will block all other Haskell threads for the duration of the call. It behaves like a safe foreign call in this respect.

  2. hWaitForInput :: Handle -> Int -> IO Bool

    base GHC.IO.Handle.Text

    Computation hWaitForInput hdl t waits until input is available on handle hdl. It returns True as soon as input is available on hdl, or False if no input is available within t milliseconds. Note that hWaitForInput waits until one or more full characters are available, which means that it needs to do decoding, and hence may fail with a decoding error. If t is less than zero, then hWaitForInput waits indefinitely. This operation may fail with:

    • isEOFError if the end of file has been reached.
    • a decoding error, if the input begins with an invalid byte sequence in this Handle's encoding.
    NOTE for GHC users: unless you use the -threaded flag, hWaitForInput hdl t where t >= 0 will block all other Haskell threads for the duration of the call. It behaves like a safe foreign call in this respect.

  3. unsafeDupablePerformIO :: IO a -> a

    base GHC.IO.Unsafe

    This version of unsafePerformIO is more efficient because it omits the check that the IO is only being performed by a single thread. Hence, when you use unsafeDupablePerformIO, there is a possibility that the IO action may be performed multiple times (on a multiprocessor), and you should therefore ensure that it gives the same results each time. It may even happen that one of the duplicated IO actions is only run partially, and then interrupted in the middle without an exception being raised. Therefore, functions like bracket cannot be used safely within unsafeDupablePerformIO.

  4. unsafePerformIO :: IO a -> a

    base GHC.IO.Unsafe

    This is the "back door" into the IO monad, allowing IO computation to be performed at any time. For this to be safe, the IO computation should be free of side effects and independent of its environment. If the I/O computation wrapped in unsafePerformIO performs side effects, then the relative order in which those side effects take place (relative to the main I/O trunk, or other calls to unsafePerformIO) is indeterminate. Furthermore, when using unsafePerformIO to cause side-effects, you should take the following precautions to ensure the side effects are performed as many times as you expect them to be. Note that these precautions are necessary for GHC, but may not be sufficient, and other compilers may require different precautions:

    • Use {-# NOINLINE foo #-} as a pragma on any function foo that calls unsafePerformIO. If the call is inlined, the I/O may be performed more than once.
    • Use the compiler flag -fno-cse to prevent common sub-expression elimination being performed on the module, which might combine two side effects that were meant to be separate. A good example is using multiple global variables (like test in the example below).
    • Make sure that the either you switch off let-floating (-fno-full-laziness), or that the call to unsafePerformIO cannot float outside a lambda. For example, if you say: f x = unsafePerformIO (newIORef []) you may get only one reference cell shared between all calls to f. Better would be f x = unsafePerformIO (newIORef [x]) because now it can't float outside the lambda.
    It is less well known that unsafePerformIO is not type safe. For example:
    test :: IORef [a]
    test = unsafePerformIO $ newIORef []
    
    main = do
    writeIORef test [42]
    bang <- readIORef test
    print (bang :: [Char])
    
    This program will core dump. This problem with polymorphic references is well known in the ML community, and does not arise with normal monadic use of references. There is no easy way to make it impossible once you use unsafePerformIO. Indeed, it is possible to write coerce :: a -> b with the help of unsafePerformIO. So be careful! WARNING: If you're looking for "a way to get a String from an 'IO String'", then unsafePerformIO is not the way to go. Learn about do-notation and the <- syntax element before you proceed.

  5. data FloatFormat

    bytestring Data.ByteString.Builder.RealFloat

    Format type for use with formatFloat and formatDouble.

  6. accursedUnutterablePerformIO :: IO a -> a

    bytestring Data.ByteString.Internal

    This "function" has a superficial similarity to unsafePerformIO but it is in fact a malevolent agent of chaos. It unpicks the seams of reality (and the IO monad) so that the normal rules no longer apply. It lulls you into thinking it is reasonable, but when you are not looking it stabs you in the back and aliases all of your mutable buffers. The carcass of many a seasoned Haskell programmer lie strewn at its feet. Witness the trail of destruction:

    Do not talk about "safe"! You do not know what is safe! Yield not to its blasphemous call! Flee traveller! Flee or you will be corrupted and devoured!

  7. deferForeignPtrAvailability :: ForeignPtr a -> IO (ForeignPtr a)

    bytestring Data.ByteString.Internal

    Most operations on a ByteString need to read from the buffer given by its ForeignPtr Word8 field. But since most operations on ByteString are (nominally) pure, their implementations cannot see the IO state thread that was used to initialize the contents of that buffer. This means that under some circumstances, these buffer-reads may be executed before the writes used to initialize the buffer are executed, with unpredictable results. deferForeignPtrAvailability exists to help solve this problem. At runtime, a call deferForeignPtrAvailability x is equivalent to pure $! x, but the former is more opaque to the simplifier, so that reads from the pointer in its result cannot be executed until the deferForeignPtrAvailability x call is complete. The opaque bits evaporate during CorePrep, so using deferForeignPtrAvailability incurs no direct overhead.

  8. fromForeignPtr :: ForeignPtr Word8 -> Int -> Int -> ByteString

    bytestring Data.ByteString.Internal

    O(1) Build a ByteString from a ForeignPtr. If you do not need the offset parameter then you should be using unsafePackCStringLen or unsafePackCStringFinalizer instead.

  9. fromForeignPtr0 :: ForeignPtr Word8 -> Int -> ByteString

    bytestring Data.ByteString.Internal

    No documentation available.

  10. nullForeignPtr :: ForeignPtr Word8

    bytestring Data.ByteString.Internal

    The 0 pointer. Used to indicate the empty Bytestring.

Page 401 of many | Previous | Next