morley-prelude-0.5.1: A custom prelude used in Morley
Safe HaskellNone
LanguageHaskell2010

Unsafe

Description

Unsafe utilities.

This module should be imported qualified.

Synopsis

Documentation

Unsafe converters between Integral types checking for overflow/underflow

fromIntegral :: (HasCallStack, Integral a, Integral b) => a -> b Source #

Unsafe converter between Integral types checking for overflow/underflow. Return value if conversion does not produce overflow/underflow and raise an exception with corresponding error message otherwise.

It is needed to replace fromIntegral which misses most of the overflow/underflow checks.

Note the function is strict in its argument.

fromInteger :: (HasCallStack, Integral a) => Integer -> a Source #

Unsafe converter between Integer and Integral types checking for overflow/underflow. Return value if conversion does not produce overflow/underflow and raise an exception with corresponding error message otherwise.

Note the function is strict in its argument.

Unsafe converters from Either for making unsafe counter-parts of safe functions

unsafe :: (HasCallStack, Buildable a) => Either a b -> b Source #

Unsafe converter from Either, which uses buildable Left to throw an exception with error.

It is primarily needed for making unsafe counter-parts of safe functions. In particular, for replacing unsafeFName x = either (error . pretty) id constructors and converters, which produce many similar functions at the call site, with unsafe . fName $ x.

unsafeM :: (MonadFail m, Buildable a) => Either a b -> m b Source #

Similar to unsafe converter, but with the use of monadic fail and returning the result wrapped in a monad.