mod package:base

Integer modulus, satisfying
(x `div` y)*y + (x `mod` y) == x
WARNING: This function is partial (because it throws when 0 is passed as the divisor) for all the integer types in base.
Modulus of natural numbers. Mod x 0 is undefined (i.e., it cannot be reduced).
A slight variation on modifyMVar_ that allows a value to be returned (b) in addition to the modified value of the MVar.
Like modifyMVar, but the IO action in the second argument is executed with asynchronous exceptions masked.
Like modifyMVar_, but the IO action in the second argument is executed with asynchronous exceptions masked.
An exception-safe wrapper for modifying the contents of an MVar. Like withMVar, modifyMVar will replace the original contents of the MVar if an exception is raised during the operation. This function is only atomic if there are no other producers for this MVar. In other words, it cannot guarantee that, by the time modifyMVar_ gets the chance to write to the MVar, the value of the MVar has not been altered by a write operation from another thread.
Generalisation of mod to any instance of Real
Mutate the contents of an IORef, combining readIORef and writeIORef. This is not an atomic update, consider using atomicModifyIORef when operating in a multithreaded environment. Be warned that modifyIORef does not apply the function strictly. This means if the program calls modifyIORef many times, but seldom uses the value, thunks will pile up in memory resulting in a space leak. This is a common mistake made when using an IORef as a counter. For example, the following will likely produce a stack overflow:
ref <- newIORef 0
replicateM_ 1000000 $ modifyIORef ref (+1)
readIORef ref >>= print
To avoid this problem, use modifyIORef' instead.
Strict version of modifyIORef. This is not an atomic update, consider using atomicModifyIORef' when operating in a multithreaded environment.
Mutate the contents of an STRef.
>>> :{
runST (do
ref <- newSTRef ""
modifySTRef ref (const "world")
modifySTRef ref (++ "!")
modifySTRef ref ("Hello, " ++)
readSTRef ref )
:}
"Hello, world!"
Be warned that modifySTRef does not apply the function strictly. This means if the program calls modifySTRef many times, but seldom uses the value, thunks will pile up in memory resulting in a space leak. This is a common mistake made when using an STRef as a counter. For example, the following will leak memory and may produce a stack overflow:
>>> import GHC.Internal.Control.Monad (replicateM_)

>>> :{
print (runST (do
ref <- newSTRef 0
replicateM_ 1000 $ modifySTRef ref (+1)
readSTRef ref ))
:}
1000
To avoid this problem, use modifySTRef' instead.
Strict version of modifySTRef
Catch any IOError that occurs in the computation and throw a modified version.
Used to implement mod for the Integral typeclass. This performs the modulo operation, satisfying
((x `div` y) * y) + (x `mod` y) == x

Example

>>> 7 `modInt` 3
1
>>> 7 `mod` 3
1
Modify the value of an MVar.
The fully-qualified name of the module where the type is declared
Used to implement mod for the Integral typeclass. This performs the modulo operation, satisfying
((x `div` y) * y) + (x `mod` y) == x

Example

>>> 7 `modInteger` 3
1
>>> 7 `mod` 3
1