on cd40d90 help sign in
50 lines 1.3 kB history raw
1-- |
2-- Module : Streamly.Internal.Control.Exception
3-- Copyright : (c) 2019 Composewell Technologies
4--
5-- License : BSD3
6-- Maintainer : streamly@composewell.com
7-- Stability : experimental
8-- Portability : GHC
9--
10-- Additional "Control.Exception" utilities.
12module Streamly.Internal.Control.Exception
13 ( assertM
14 , verify
15 , verifyM
16 )
17where
19import Control.Exception (assert)
21-- Like 'assert' but returns @()@ in an 'Applicative' context so that it can be
22-- used as an independent statement in a @do@ block.
23--
24-- /Internal/
25--
26{-# INLINE assertM #-}
27assertM :: Applicative f => Bool -> f ()
28assertM predicate = assert predicate (pure ())
30-- | Like 'assert' but is not removed by the compiler, it is always present in
31-- production code.
32--
33-- /Internal/
34--
35{-# INLINE verify #-}
36verify :: Bool -> a -> a
37verify predicate val =
38 if predicate
39 -- XXX it would be nice if we can print the predicate expr.
40 then error "verify failed"
41 else val
43-- Like 'verify' but returns @()@ in an 'Applicative' context so that it can be
44-- used as an independent statement in a @do@ block.
45--
46-- /Internal/
47--
48{-# INLINE verifyM #-}
49verifyM :: Applicative f => Bool -> f ()
50verifyM predicate = verify predicate (pure ())