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.
hWaitForInput :: Handle -> Int -> IO Boolbase 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.
hWaitForInput :: Handle -> Int -> IO Boolbase 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.
unsafeDupablePerformIO :: IO a -> abase 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.
-
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.
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. -
bytestring Data.ByteString.Builder.RealFloat Format type for use with formatFloat and formatDouble.
accursedUnutterablePerformIO :: IO a -> abytestring 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:
- https://github.com/haskell/bytestring/commit/71c4b438c675aa360c79d79acc9a491e7bbc26e7
- https://github.com/haskell/bytestring/commit/210c656390ae617d9ee3b8bcff5c88dd17cef8da
- https://github.com/haskell/aeson/commit/720b857e2e0acf2edc4f5512f2b217a89449a89d
- https://ghc.haskell.org/trac/ghc/ticket/3486
- https://ghc.haskell.org/trac/ghc/ticket/3487
- https://ghc.haskell.org/trac/ghc/ticket/7270
- https://gitlab.haskell.org/ghc/ghc/-/issues/22204
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.
fromForeignPtr :: ForeignPtr Word8 -> Int -> Int -> ByteStringbytestring 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.
fromForeignPtr0 :: ForeignPtr Word8 -> Int -> ByteStringbytestring Data.ByteString.Internal No documentation available.
nullForeignPtr :: ForeignPtr Word8bytestring Data.ByteString.Internal The 0 pointer. Used to indicate the empty Bytestring.