on e856425 help sign in
38 lines 944 B 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 ( verify
14 , verifyM
15 )
16where
18-- | Like 'assert' but is not removed by the compiler, it is always present in
19-- production code.
20--
21-- /Pre-release/
22--
23{-# INLINE verify #-}
24verify :: Bool -> a -> a
25verify predicate val =
26 if predicate
27 -- XXX it would be nice if we can print the predicate expr.
28 then error "verify failed"
29 else val
31-- Like 'verify' but returns @()@ in an 'Applicative' context so that it can be
32-- used as an independent statement in a @do@ block.
33--
34-- /Pre-release/
35--
36{-# INLINE verifyM #-}
37verifyM :: Applicative f => Bool -> f ()
38verifyM predicate = verify predicate (pure ())