1{-# LANGUAGE CPP #-} 2{-# LANGUAGE Rank2Types #-} 3{-# LANGUAGE FlexibleInstances #-} 4{-# LANGUAGE ScopedTypeVariables #-} 5{-# LANGUAGE MultiParamTypeClasses #-} 6{-# LANGUAGE NoMonomorphismRestriction #-} 7 8#ifdef TRUSTWORTHY 9{-# LANGUAGE Trustworthy #-} 10#endif 11 12#if __GLASGOW_HASKELL__ >= 710 13{-# LANGUAGE PatternSynonyms #-} 14{-# LANGUAGE ViewPatterns #-} 15#endif 16 17#include "lens-common.h" 18 19#if !(MIN_VERSION_exceptions(0,4,0)) 20#define MonadThrow MonadCatch 21#endif 22 23----------------------------------------------------------------------------- 24-- | 25-- Module : Control.Exception.Lens 26-- Copyright : (C) 2012-16 Edward Kmett 27-- License : BSD-style (see the file LICENSE) 28-- Maintainer : Edward Kmett <ekmett@gmail.com> 29-- Stability : provisional 30-- Portability : Control.Exception 31-- 32-- @Control.Exception@ provides an example of a large open hierarchy 33-- that we can model with prisms and isomorphisms. 34-- 35-- Additional combinators for working with 'IOException' results can 36-- be found in "System.IO.Error.Lens". 37-- 38-- The combinators in this module have been generalized to work with 39-- 'MonadCatch' instead of just 'IO'. This enables them to be used 40-- more easily in 'Monad' transformer stacks. 41---------------------------------------------------------------------------- 42module Control.Exception.Lens 43 ( 44 -- * Handling 45 catching, catching_ 46 , handling, handling_ 47 -- * Trying 48 , trying, trying_ 49 -- * Throwing 50 , throwing 51 , throwing_ 52 , throwingM 53 , throwingTo 54 -- * Mapping 55 , mappedException, mappedException' 56 -- * Exceptions 57 , exception 58#if __GLASGOW_HASKELL__ >= 710 59 , pattern Exception 60#endif 61 -- * Exception Handlers 62 , Handleable(..) 63 -- ** IOExceptions 64 , AsIOException(..) 65#if __GLASGOW_HASKELL__ >= 710 66 , pattern IOException_ 67#endif 68 -- ** Arithmetic Exceptions 69 , AsArithException(..) 70 , _Overflow, _Underflow, _LossOfPrecision, _DivideByZero, _Denormal 71 , _RatioZeroDenominator 72#if __GLASGOW_HASKELL__ >= 710 73 , pattern ArithException_ 74 , pattern Overflow_ 75 , pattern Underflow_ 76 , pattern LossOfPrecision_ 77 , pattern DivideByZero_ 78 , pattern Denormal_ 79 , pattern RatioZeroDenominator_ 80#endif 81 -- ** Array Exceptions 82 , AsArrayException(..) 83 , _IndexOutOfBounds 84 , _UndefinedElement 85#if __GLASGOW_HASKELL__ >= 710 86 , pattern ArrayException_ 87 , pattern IndexOutOfBounds_ 88 , pattern UndefinedElement_ 89#endif 90 -- ** Assertion Failed 91 , AsAssertionFailed(..) 92#if __GLASGOW_HASKELL__ >= 710 93 , pattern AssertionFailed__ 94 , pattern AssertionFailed_ 95#endif 96 -- ** Async Exceptions 97 , AsAsyncException(..) 98 , _StackOverflow 99 , _HeapOverflow 100 , _ThreadKilled 101 , _UserInterrupt 102#if __GLASGOW_HASKELL__ >= 710 103 , pattern AsyncException_ 104 , pattern StackOverflow_ 105 , pattern HeapOverflow_ 106 , pattern ThreadKilled_ 107 , pattern UserInterrupt_ 108#endif 109 -- ** Non-Termination 110 , AsNonTermination(..) 111#if __GLASGOW_HASKELL__ >= 710 112 , pattern NonTermination__ 113 , pattern NonTermination_ 114#endif 115 -- ** Nested Atomically 116 , AsNestedAtomically(..) 117#if __GLASGOW_HASKELL__ >= 710 118 , pattern NestedAtomically__ 119 , pattern NestedAtomically_ 120#endif 121 -- ** Blocked Indefinitely 122 -- *** on MVar 123 , AsBlockedIndefinitelyOnMVar(..) 124#if __GLASGOW_HASKELL__ >= 710 125 , pattern BlockedIndefinitelyOnMVar__ 126 , pattern BlockedIndefinitelyOnMVar_ 127#endif 128 -- *** on STM 129 , AsBlockedIndefinitelyOnSTM(..) 130#if __GLASGOW_HASKELL__ >= 710 131 , pattern BlockedIndefinitelyOnSTM__ 132 , pattern BlockedIndefinitelyOnSTM_ 133#endif 134 -- ** Deadlock 135 , AsDeadlock(..) 136#if __GLASGOW_HASKELL__ >= 710 137 , pattern Deadlock__ 138 , pattern Deadlock_ 139#endif 140 -- ** No Such Method 141 , AsNoMethodError(..) 142#if __GLASGOW_HASKELL__ >= 710 143 , pattern NoMethodError__ 144 , pattern NoMethodError_ 145#endif 146 -- ** Pattern Match Failure 147 , AsPatternMatchFail(..) 148#if __GLASGOW_HASKELL__ >= 710 149 , pattern PatternMatchFail__ 150 , pattern PatternMatchFail_ 151#endif 152 -- ** Record 153 , AsRecConError(..) 154 , AsRecSelError(..) 155 , AsRecUpdError(..) 156#if __GLASGOW_HASKELL__ >= 710 157 , pattern RecConError__ 158 , pattern RecConError_ 159 , pattern RecSelError__ 160 , pattern RecSelError_ 161 , pattern RecUpdError__ 162 , pattern RecUpdError_ 163#endif 164 -- ** Error Call 165 , AsErrorCall(..) 166#if __GLASGOW_HASKELL__ >= 710 167 , pattern ErrorCall__ 168 , pattern ErrorCall_ 169#endif 170#if MIN_VERSION_base(4,8,0) 171 -- ** Allocation Limit Exceeded 172 , AsAllocationLimitExceeded(..) 173 , pattern AllocationLimitExceeded__ 174 , pattern AllocationLimitExceeded_ 175#endif 176#if MIN_VERSION_base(4,9,0) 177 -- ** Type Error 178 , AsTypeError(..) 179 , pattern TypeError__ 180 , pattern TypeError_ 181#endif 182#if MIN_VERSION_base(4,10,0) 183 -- ** Compaction Failed 184 , AsCompactionFailed(..) 185 , pattern CompactionFailed__ 186 , pattern CompactionFailed_ 187#endif 188 -- * Handling Exceptions 189 , AsHandlingException(..) 190#if __GLASGOW_HASKELL__ >= 710 191 , pattern HandlingException__ 192 , pattern HandlingException_ 193#endif 194 ) where 195 196import Control.Applicative 197import Control.Monad 198import Control.Monad.IO.Class 199import Control.Monad.Catch as Catch 200import Control.Exception as Exception hiding (try, tryJust, catchJust) 201import Control.Lens 202import Control.Lens.Internal.Exception 203import Data.Monoid 204import GHC.Conc (ThreadId) 205import Prelude 206 ( const, either, flip, id 207 , (.) 208 , Maybe(..), Either(..), String 209#if __GLASGOW_HASKELL__ >= 710 210 , Bool(..) 211#endif 212 ) 213 214-- $setup 215-- >>> :set -XNoOverloadedStrings 216-- >>> import Control.Lens 217-- >>> import Control.Applicative 218-- >>> :m + Control.Exception Control.Monad Data.List Prelude 219 220------------------------------------------------------------------------------ 221-- Exceptions as Prisms 222------------------------------------------------------------------------------ 223 224-- | Traverse the strongly typed 'Exception' contained in 'SomeException' where the type of your function matches 225-- the desired 'Exception'. 226-- 227-- @ 228-- 'exception' :: ('Applicative' f, 'Exception' a) 229-- => (a -> f a) -> 'SomeException' -> f 'SomeException' 230-- @ 231exception :: Exception a => Prism' SomeException a 232exception = prism' toException fromException 233{-# INLINE exception #-} 234 235#if __GLASGOW_HASKELL__ >= 710 236pattern Exception e <- (preview exception -> Just e) where 237 Exception e = review exception e 238#endif 239 240------------------------------------------------------------------------------ 241-- Catching 242------------------------------------------------------------------------------ 243 244-- | Catch exceptions that match a given 'Prism' (or any 'Fold', really). 245-- 246-- >>> catching _AssertionFailed (assert False (return "uncaught")) $ \ _ -> return "caught" 247-- "caught" 248-- 249-- @ 250-- 'catching' :: 'MonadCatch' m => 'Prism'' 'SomeException' a -> m r -> (a -> m r) -> m r 251-- 'catching' :: 'MonadCatch' m => 'Lens'' 'SomeException' a -> m r -> (a -> m r) -> m r 252-- 'catching' :: 'MonadCatch' m => 'Traversal'' 'SomeException' a -> m r -> (a -> m r) -> m r 253-- 'catching' :: 'MonadCatch' m => 'Iso'' 'SomeException' a -> m r -> (a -> m r) -> m r 254-- 'catching' :: 'MonadCatch' m => 'Getter' 'SomeException' a -> m r -> (a -> m r) -> m r 255-- 'catching' :: 'MonadCatch' m => 'Fold' 'SomeException' a -> m r -> (a -> m r) -> m r 256-- @ 257catching :: MonadCatch m => Getting (First a) SomeException a -> m r -> (a -> m r) -> m r 258catching l = catchJust (preview l) 259{-# INLINE catching #-} 260 261-- | Catch exceptions that match a given 'Prism' (or any 'Getter'), discarding 262-- the information about the match. This is particularly useful when you have 263-- a @'Prism'' e ()@ where the result of the 'Prism' or 'Fold' isn't 264-- particularly valuable, just the fact that it matches. 265-- 266-- >>> catching_ _AssertionFailed (assert False (return "uncaught")) $ return "caught" 267-- "caught" 268-- 269-- @ 270-- 'catching_' :: 'MonadCatch' m => 'Prism'' 'SomeException' a -> m r -> m r -> m r 271-- 'catching_' :: 'MonadCatch' m => 'Lens'' 'SomeException' a -> m r -> m r -> m r 272-- 'catching_' :: 'MonadCatch' m => 'Traversal'' 'SomeException' a -> m r -> m r -> m r 273-- 'catching_' :: 'MonadCatch' m => 'Iso'' 'SomeException' a -> m r -> m r -> m r 274-- 'catching_' :: 'MonadCatch' m => 'Getter' 'SomeException' a -> m r -> m r -> m r 275-- 'catching_' :: 'MonadCatch' m => 'Fold' 'SomeException' a -> m r -> m r -> m r 276-- @ 277catching_ :: MonadCatch m => Getting (First a) SomeException a -> m r -> m r -> m r 278catching_ l a b = catchJust (preview l) a (const b) 279{-# INLINE catching_ #-} 280 281------------------------------------------------------------------------------ 282-- Handling 283------------------------------------------------------------------------------ 284 285-- | A version of 'catching' with the arguments swapped around; useful in 286-- situations where the code for the handler is shorter. 287-- 288-- >>> handling _NonTermination (\_ -> return "caught") $ throwIO NonTermination 289-- "caught" 290-- 291-- @ 292-- 'handling' :: 'MonadCatch' m => 'Prism'' 'SomeException' a -> (a -> m r) -> m r -> m r 293-- 'handling' :: 'MonadCatch' m => 'Lens'' 'SomeException' a -> (a -> m r) -> m r -> m r 294-- 'handling' :: 'MonadCatch' m => 'Traversal'' 'SomeException' a -> (a -> m r) -> m r -> m r 295-- 'handling' :: 'MonadCatch' m => 'Iso'' 'SomeException' a -> (a -> m r) -> m r -> m r 296-- 'handling' :: 'MonadCatch' m => 'Fold' 'SomeException' a -> (a -> m r) -> m r -> m r 297-- 'handling' :: 'MonadCatch' m => 'Getter' 'SomeException' a -> (a -> m r) -> m r -> m r 298-- @ 299handling :: MonadCatch m => Getting (First a) SomeException a -> (a -> m r) -> m r -> m r 300handling l = flip (catching l) 301{-# INLINE handling #-} 302 303-- | A version of 'catching_' with the arguments swapped around; useful in 304-- situations where the code for the handler is shorter. 305-- 306-- >>> handling_ _NonTermination (return "caught") $ throwIO NonTermination 307-- "caught" 308-- 309-- @ 310-- 'handling_' :: 'MonadCatch' m => 'Prism'' 'SomeException' a -> m r -> m r -> m r 311-- 'handling_' :: 'MonadCatch' m => 'Lens'' 'SomeException' a -> m r -> m r -> m r 312-- 'handling_' :: 'MonadCatch' m => 'Traversal'' 'SomeException' a -> m r -> m r -> m r 313-- 'handling_' :: 'MonadCatch' m => 'Iso'' 'SomeException' a -> m r -> m r -> m r 314-- 'handling_' :: 'MonadCatch' m => 'Getter' 'SomeException' a -> m r -> m r -> m r 315-- 'handling_' :: 'MonadCatch' m => 'Fold' 'SomeException' a -> m r -> m r -> m r 316-- @ 317handling_ :: MonadCatch m => Getting (First a) SomeException a -> m r -> m r -> m r 318handling_ l = flip (catching_ l) 319{-# INLINE handling_ #-} 320 321------------------------------------------------------------------------------ 322-- Trying 323------------------------------------------------------------------------------ 324 325-- | A variant of 'Control.Exception.try' that takes a 'Prism' (or any 'Fold') to select which 326-- exceptions are caught (c.f. 'Control.Exception.tryJust', 'Control.Exception.catchJust'). If the 327-- 'Exception' does not match the predicate, it is re-thrown. 328-- 329-- @ 330-- 'trying' :: 'MonadCatch' m => 'Prism'' 'SomeException' a -> m r -> m ('Either' a r) 331-- 'trying' :: 'MonadCatch' m => 'Lens'' 'SomeException' a -> m r -> m ('Either' a r) 332-- 'trying' :: 'MonadCatch' m => 'Traversal'' 'SomeException' a -> m r -> m ('Either' a r) 333-- 'trying' :: 'MonadCatch' m => 'Iso'' 'SomeException' a -> m r -> m ('Either' a r) 334-- 'trying' :: 'MonadCatch' m => 'Getter' 'SomeException' a -> m r -> m ('Either' a r) 335-- 'trying' :: 'MonadCatch' m => 'Fold' 'SomeException' a -> m r -> m ('Either' a r) 336-- @ 337trying :: MonadCatch m => Getting (First a) SomeException a -> m r -> m (Either a r) 338trying l = tryJust (preview l) 339{-# INLINE trying #-} 340 341-- | A version of 'trying' that discards the specific exception thrown. 342-- 343-- @ 344-- 'trying_' :: 'MonadCatch' m => 'Prism'' 'SomeException' a -> m r -> m (Maybe r) 345-- 'trying_' :: 'MonadCatch' m => 'Lens'' 'SomeException' a -> m r -> m (Maybe r) 346-- 'trying_' :: 'MonadCatch' m => 'Traversal'' 'SomeException' a -> m r -> m (Maybe r) 347-- 'trying_' :: 'MonadCatch' m => 'Iso'' 'SomeException' a -> m r -> m (Maybe r) 348-- 'trying_' :: 'MonadCatch' m => 'Getter' 'SomeException' a -> m r -> m (Maybe r) 349-- 'trying_' :: 'MonadCatch' m => 'Fold' 'SomeException' a -> m r -> m (Maybe r) 350-- @ 351trying_ :: MonadCatch m => Getting (First a) SomeException a -> m r -> m (Maybe r) 352trying_ l m = preview _Right `liftM` trying l m 353{-# INLINE trying_ #-} 354 355------------------------------------------------------------------------------ 356-- Throwing 357------------------------------------------------------------------------------ 358 359-- | Throw an 'Exception' described by a 'Prism'. Exceptions may be thrown from 360-- purely functional code, but may only be caught within the 'IO' 'Monad'. 361-- 362-- @ 363-- 'throwing' l ≡ 'reviews' l 'throw' 364-- @ 365-- 366-- @ 367-- 'throwing' :: 'Prism'' 'SomeException' t -> t -> r 368-- 'throwing' :: 'Iso'' 'SomeException' t -> t -> r 369-- @ 370throwing :: AReview SomeException b -> b -> r 371throwing l = reviews l Exception.throw 372{-# INLINE throwing #-} 373 374-- | Similar to 'throwing' but specialised for the common case of 375-- error constructors with no arguments. 376-- 377-- @ 378-- data MyError = Foo | Bar 379-- makePrisms ''MyError 380-- 'throwing_' _Foo :: 'MonadError' MyError m => m a 381-- @ 382throwing_ :: AReview SomeException () -> m x 383throwing_ l = throwing l () 384{-# INLINE throwing_ #-} 385 386-- | A variant of 'throwing' that can only be used within the 'IO' 'Monad' 387-- (or any other 'MonadCatch' instance) to throw an 'Exception' described 388-- by a 'Prism'. 389-- 390-- Although 'throwingM' has a type that is a specialization of the type of 391-- 'throwing', the two functions are subtly different: 392-- 393-- @ 394-- 'throwing' l e \`seq\` x ≡ 'throwing' e 395-- 'throwingM' l e \`seq\` x ≡ x 396-- @ 397-- 398-- The first example will cause the 'Exception' @e@ to be raised, whereas the 399-- second one won't. In fact, 'throwingM' will only cause an 'Exception' to 400-- be raised when it is used within the 'MonadCatch' instance. The 'throwingM' 401-- variant should be used in preference to 'throwing' to raise an 'Exception' 402-- within the 'Monad' because it guarantees ordering with respect to other 403-- monadic operations, whereas 'throwing' does not. 404-- 405-- @ 406-- 'throwingM' l ≡ 'reviews' l 'CatchIO.throw' 407-- @ 408-- 409-- @ 410-- 'throwingM' :: 'MonadThrow' m => 'Prism'' 'SomeException' t -> t -> m r 411-- 'throwingM' :: 'MonadThrow' m => 'Iso'' 'SomeException' t -> t -> m r 412-- @ 413throwingM :: MonadThrow m => AReview SomeException b -> b -> m r 414throwingM l = reviews l throwM 415{-# INLINE throwingM #-} 416 417-- | 'throwingTo' raises an 'Exception' specified by a 'Prism' in the target thread. 418-- 419-- @ 420-- 'throwingTo' thread l ≡ 'reviews' l ('throwTo' thread) 421-- @ 422-- 423-- @ 424-- 'throwingTo' :: 'ThreadId' -> 'Prism'' 'SomeException' t -> t -> m a 425-- 'throwingTo' :: 'ThreadId' -> 'Iso'' 'SomeException' t -> t -> m a 426-- @ 427throwingTo :: MonadIO m => ThreadId -> AReview SomeException b -> b -> m () 428throwingTo tid l = reviews l (liftIO . throwTo tid) 429{-# INLINE throwingTo #-} 430 431---------------------------------------------------------------------------- 432-- Mapping 433---------------------------------------------------------------------------- 434 435-- | This 'Setter' can be used to purely map over the 'Exception's an 436-- arbitrary expression might throw; it is a variant of 'mapException' in 437-- the same way that 'mapped' is a variant of 'fmap'. 438-- 439-- > 'mapException' ≡ 'over' 'mappedException' 440-- 441-- This view that every Haskell expression can be regarded as carrying a bag 442-- of 'Exception's is detailed in “A Semantics for Imprecise Exceptions” by 443-- Peyton Jones & al. at PLDI ’99. 444-- 445-- The following maps failed assertions to arithmetic overflow: 446-- 447-- >>> handling _Overflow (\_ -> return "caught") $ assert False (return "uncaught") & mappedException %~ \ (AssertionFailed _) -> Overflow 448-- "caught" 449mappedException :: (Exception e, Exception e') => Setter s s e e' 450mappedException = sets mapException 451{-# INLINE mappedException #-} 452 453-- | This is a type restricted version of 'mappedException', which avoids 454-- the type ambiguity in the input 'Exception' when using 'set'. 455-- 456-- The following maps any exception to arithmetic overflow: 457-- 458-- >>> handling _Overflow (\_ -> return "caught") $ assert False (return "uncaught") & mappedException' .~ Overflow 459-- "caught" 460mappedException' :: Exception e' => Setter s s SomeException e' 461mappedException' = mappedException 462{-# INLINE mappedException' #-} 463 464---------------------------------------------------------------------------- 465-- IOException 466---------------------------------------------------------------------------- 467 468-- | Exceptions that occur in the 'IO' 'Monad'. An 'IOException' records a 469-- more specific error type, a descriptive string and maybe the handle that was 470-- used when the error was flagged. 471-- 472-- Due to their richer structure relative to other exceptions, these have 473-- a more carefully overloaded signature. 474class AsIOException t where 475 -- | Unfortunately the name 'ioException' is taken by @base@ for 476 -- throwing IOExceptions. 477 -- 478 -- @ 479 -- '_IOException' :: 'Prism'' 'IOException' 'IOException' 480 -- '_IOException' :: 'Prism'' 'SomeException' 'IOException' 481 -- @ 482 -- 483 -- Many combinators for working with an 'IOException' are available 484 -- in "System.IO.Error.Lens". 485 _IOException :: Prism' t IOException 486 487instance AsIOException IOException where 488 _IOException = id 489 {-# INLINE _IOException #-} 490 491instance AsIOException SomeException where 492 _IOException = exception 493 {-# INLINE _IOException #-} 494 495#if __GLASGOW_HASKELL__ >= 710 496pattern IOException_ a <- (preview _IOException -> Just a) where 497 IOException_ a = review _IOException a 498#endif 499 500---------------------------------------------------------------------------- 501-- ArithException 502---------------------------------------------------------------------------- 503 504-- | Arithmetic exceptions. 505class AsArithException t where 506 -- | 507 -- @ 508 -- '_ArithException' :: 'Prism'' 'ArithException' 'ArithException' 509 -- '_ArithException' :: 'Prism'' 'SomeException' 'ArithException' 510 -- @ 511 _ArithException :: Prism' t ArithException 512 513#if __GLASGOW_HASKELL__ >= 710 514pattern ArithException_ a <- (preview _ArithException -> Just a) where 515 ArithException_ a = review _ArithException a 516#endif 517 518instance AsArithException ArithException where 519 _ArithException = id 520 {-# INLINE _ArithException #-} 521 522instance AsArithException SomeException where 523 _ArithException = exception 524 {-# INLINE _ArithException #-} 525 526-- | Handle arithmetic '_Overflow'. 527-- 528-- @ 529-- '_Overflow' ≡ '_ArithException' '.' '_Overflow' 530-- @ 531-- 532-- @ 533-- '_Overflow' :: 'Prism'' 'ArithException' 'ArithException' 534-- '_Overflow' :: 'Prism'' 'SomeException' 'ArithException' 535-- @ 536_Overflow :: AsArithException t => Prism' t () 537_Overflow = _ArithException . dimap seta (either id id) . right' . rmap (Overflow <$) where 538 seta Overflow = Right () 539 seta t = Left (pure t) 540{-# INLINE _Overflow #-} 541 542#if __GLASGOW_HASKELL__ >= 710 543pattern Overflow_ <- (has _Overflow -> True) where 544 Overflow_ = review _Overflow () 545#endif 546 547-- | Handle arithmetic '_Underflow'. 548-- 549-- @ 550-- '_Underflow' ≡ '_ArithException' '.' '_Underflow' 551-- @ 552-- 553-- @ 554-- '_Underflow' :: 'Prism'' 'ArithException' 'ArithException' 555-- '_Underflow' :: 'Prism'' 'SomeException' 'ArithException' 556-- @ 557_Underflow :: AsArithException t => Prism' t () 558_Underflow = _ArithException . dimap seta (either id id) . right' . rmap (Underflow <$) where 559 seta Underflow = Right () 560 seta t = Left (pure t) 561{-# INLINE _Underflow #-} 562 563#if __GLASGOW_HASKELL__ >= 710 564pattern Underflow_ <- (has _Underflow -> True) where 565 Underflow_ = review _Underflow () 566#endif 567 568-- | Handle arithmetic loss of precision. 569-- 570-- @ 571-- '_LossOfPrecision' ≡ '_ArithException' '.' '_LossOfPrecision' 572-- @ 573-- 574-- @ 575-- '_LossOfPrecision' :: 'Prism'' 'ArithException' 'ArithException' 576-- '_LossOfPrecision' :: 'Prism'' 'SomeException' 'ArithException' 577-- @ 578_LossOfPrecision :: AsArithException t => Prism' t () 579_LossOfPrecision = _ArithException . dimap seta (either id id) . right' . rmap (LossOfPrecision <$) where 580 seta LossOfPrecision = Right () 581 seta t = Left (pure t) 582{-# INLINE _LossOfPrecision #-} 583 584#if __GLASGOW_HASKELL__ >= 710 585pattern LossOfPrecision_ <- (has _LossOfPrecision -> True) where 586 LossOfPrecision_ = review _LossOfPrecision () 587#endif 588 589-- | Handle division by zero. 590-- 591-- @ 592-- '_DivideByZero' ≡ '_ArithException' '.' '_DivideByZero' 593-- @ 594-- 595-- @ 596-- '_DivideByZero' :: 'Prism'' 'ArithException' 'ArithException' 597-- '_DivideByZero' :: 'Prism'' 'SomeException' 'ArithException' 598-- @ 599_DivideByZero :: AsArithException t => Prism' t () 600_DivideByZero = _ArithException . dimap seta (either id id) . right' . rmap (DivideByZero <$) where 601 seta DivideByZero = Right () 602 seta t = Left (pure t) 603{-# INLINE _DivideByZero #-} 604 605#if __GLASGOW_HASKELL__ >= 710 606pattern DivideByZero_ <- (has _DivideByZero -> True) where 607 DivideByZero_ = review _DivideByZero () 608#endif 609 610-- | Handle exceptional _Denormalized floating pure. 611-- 612-- @ 613-- '_Denormal' ≡ '_ArithException' '.' '_Denormal' 614-- @ 615-- 616-- @ 617-- '_Denormal' :: 'Prism'' 'ArithException' 'ArithException' 618-- '_Denormal' :: 'Prism'' 'SomeException' 'ArithException' 619-- @ 620_Denormal :: AsArithException t => Prism' t () 621_Denormal = _ArithException . dimap seta (either id id) . right' . rmap (Denormal <$) where 622 seta Denormal = Right () 623 seta t = Left (pure t) 624{-# INLINE _Denormal #-} 625 626#if __GLASGOW_HASKELL__ >= 710 627pattern Denormal_ <- (has _Denormal -> True) where 628 Denormal_ = review _Denormal () 629#endif 630 631-- | 632-- 633-- @ 634-- '_RatioZeroDenominator' ≡ '_ArithException' '.' '_RatioZeroDenominator' 635-- @ 636-- 637-- @ 638-- '_RatioZeroDenominator' :: 'Prism'' 'ArithException' 'ArithException' 639-- '_RatioZeroDenominator' :: 'Prism'' 'SomeException' 'ArithException' 640-- @ 641_RatioZeroDenominator :: AsArithException t => Prism' t () 642_RatioZeroDenominator = _ArithException . dimap seta (either id id) . right' . rmap (RatioZeroDenominator <$) where 643 seta RatioZeroDenominator = Right () 644 seta t = Left (pure t) 645{-# INLINE _RatioZeroDenominator #-} 646 647#if __GLASGOW_HASKELL__ >= 710 648pattern RatioZeroDenominator_ <- (has _RatioZeroDenominator -> True) where 649 RatioZeroDenominator_ = review _RatioZeroDenominator () 650#endif 651 652---------------------------------------------------------------------------- 653-- ArrayException 654---------------------------------------------------------------------------- 655 656-- | Exceptions generated by array operations. 657class AsArrayException t where 658 -- | Extract information about an 'ArrayException'. 659 -- 660 -- @ 661 -- '_ArrayException' :: 'Prism'' 'ArrayException' 'ArrayException' 662 -- '_ArrayException' :: 'Prism'' 'SomeException' 'ArrayException' 663 -- @ 664 _ArrayException :: Prism' t ArrayException 665 666instance AsArrayException ArrayException where 667 _ArrayException = id 668 {-# INLINE _ArrayException #-} 669 670instance AsArrayException SomeException where 671 _ArrayException = exception 672 {-# INLINE _ArrayException #-} 673 674#if __GLASGOW_HASKELL__ >= 710 675pattern ArrayException_ e <- (preview _ArrayException -> Just e) where 676 ArrayException_ e = review _ArrayException e 677#endif 678 679-- | An attempt was made to index an array outside its declared bounds. 680-- 681-- @ 682-- '_IndexOutOfBounds' ≡ '_ArrayException' '.' '_IndexOutOfBounds' 683-- @ 684-- 685-- @ 686-- '_IndexOutOfBounds' :: 'Prism'' 'ArrayException' 'String' 687-- '_IndexOutOfBounds' :: 'Prism'' 'SomeException' 'String' 688-- @ 689_IndexOutOfBounds :: AsArrayException t => Prism' t String 690_IndexOutOfBounds = _ArrayException . dimap seta (either id id) . right' . rmap (fmap IndexOutOfBounds) where 691 seta (IndexOutOfBounds r) = Right r 692 seta t = Left (pure t) 693{-# INLINE _IndexOutOfBounds #-} 694 695#if __GLASGOW_HASKELL__ >= 710 696pattern IndexOutOfBounds_ e <- (preview _IndexOutOfBounds -> Just e) where 697 IndexOutOfBounds_ e = review _IndexOutOfBounds e 698#endif 699 700-- | An attempt was made to evaluate an element of an array that had not been initialized. 701-- 702-- @ 703-- '_UndefinedElement' ≡ '_ArrayException' '.' '_UndefinedElement' 704-- @ 705-- 706-- @ 707-- '_UndefinedElement' :: 'Prism'' 'ArrayException' 'String' 708-- '_UndefinedElement' :: 'Prism'' 'SomeException' 'String' 709-- @ 710_UndefinedElement :: AsArrayException t => Prism' t String 711_UndefinedElement = _ArrayException . dimap seta (either id id) . right' . rmap (fmap UndefinedElement) where 712 seta (UndefinedElement r) = Right r 713 seta t = Left (pure t) 714{-# INLINE _UndefinedElement #-} 715 716#if __GLASGOW_HASKELL__ >= 710 717pattern UndefinedElement_ e <- (preview _UndefinedElement -> Just e) where 718 UndefinedElement_ e = review _UndefinedElement e 719#endif 720 721---------------------------------------------------------------------------- 722-- AssertionFailed 723---------------------------------------------------------------------------- 724 725-- | 'assert' was applied to 'Prelude.False'. 726class AsAssertionFailed t where 727 -- | 728 -- @ 729 -- '__AssertionFailed' :: 'Prism'' 'AssertionFailed' 'AssertionFailed' 730 -- '__AssertionFailed' :: 'Prism'' 'SomeException' 'AssertionFailed' 731 -- @ 732 __AssertionFailed :: Prism' t AssertionFailed 733 734 -- | This 'Exception' contains provides information about what assertion failed in the 'String'. 735 -- 736 -- >>> handling _AssertionFailed (\ xs -> "caught" <$ guard ("<interactive>" `isInfixOf` xs) ) $ assert False (return "uncaught") 737 -- "caught" 738 -- 739 -- @ 740 -- '_AssertionFailed' :: 'Prism'' 'AssertionFailed' 'String' 741 -- '_AssertionFailed' :: 'Prism'' 'SomeException' 'String' 742 -- @ 743 _AssertionFailed :: Prism' t String 744 _AssertionFailed = __AssertionFailed._AssertionFailed 745 {-# INLINE _AssertionFailed #-} 746 747instance AsAssertionFailed AssertionFailed where 748 __AssertionFailed = id 749 {-# INLINE __AssertionFailed #-} 750 751 _AssertionFailed = _Wrapping AssertionFailed 752 {-# INLINE _AssertionFailed #-} 753 754instance AsAssertionFailed SomeException where 755 __AssertionFailed = exception 756 {-# INLINE __AssertionFailed #-} 757 758#if __GLASGOW_HASKELL__ >= 710 759pattern AssertionFailed__ e <- (preview __AssertionFailed -> Just e) where 760 AssertionFailed__ e = review __AssertionFailed e 761 762pattern AssertionFailed_ e <- (preview _AssertionFailed -> Just e) where 763 AssertionFailed_ e = review _AssertionFailed e 764#endif 765 766---------------------------------------------------------------------------- 767-- AsyncException 768---------------------------------------------------------------------------- 769 770-- | Asynchronous exceptions. 771class AsAsyncException t where 772 -- | There are several types of 'AsyncException'. 773 -- 774 -- @ 775 -- '_AsyncException' :: 'Equality'' 'AsyncException' 'AsyncException' 776 -- '_AsyncException' :: 'Prism'' 'SomeException' 'AsyncException' 777 -- @ 778 _AsyncException :: Prism' t AsyncException 779 780instance AsAsyncException AsyncException where 781 _AsyncException = id 782 {-# INLINE _AsyncException #-} 783 784instance AsAsyncException SomeException where 785 _AsyncException = exception 786 {-# INLINE _AsyncException #-} 787 788#if __GLASGOW_HASKELL__ >= 710 789pattern AsyncException_ e <- (preview _AsyncException -> Just e) where 790 AsyncException_ e = review _AsyncException e 791#endif 792 793-- | The current thread's stack exceeded its limit. Since an 'Exception' has 794-- been raised, the thread's stack will certainly be below its limit again, 795-- but the programmer should take remedial action immediately. 796-- 797-- @ 798-- '_StackOverflow' :: 'Prism'' 'AsyncException' () 799-- '_StackOverflow' :: 'Prism'' 'SomeException' () 800-- @ 801_StackOverflow :: AsAsyncException t => Prism' t () 802_StackOverflow = _AsyncException . dimap seta (either id id) . right' . rmap (StackOverflow <$) where 803 seta StackOverflow = Right () 804 seta t = Left (pure t) 805{-# INLINE _StackOverflow #-} 806 807#if __GLASGOW_HASKELL__ >= 710 808pattern StackOverflow_ <- (has _StackOverflow -> True) where 809 StackOverflow_ = review _StackOverflow () 810#endif 811 812-- | The program's heap is reaching its limit, and the program should take action 813-- to reduce the amount of live data it has. 814-- 815-- Notes: 816-- 817-- * It is undefined which thread receives this 'Exception'. 818-- 819-- * GHC currently does not throw 'HeapOverflow' exceptions. 820-- 821-- @ 822-- '_HeapOverflow' :: 'Prism'' 'AsyncException' () 823-- '_HeapOverflow' :: 'Prism'' 'SomeException' () 824-- @ 825_HeapOverflow :: AsAsyncException t => Prism' t () 826_HeapOverflow = _AsyncException . dimap seta (either id id) . right' . rmap (HeapOverflow <$) where 827 seta HeapOverflow = Right () 828 seta t = Left (pure t) 829{-# INLINE _HeapOverflow #-} 830 831#if __GLASGOW_HASKELL__ >= 710 832pattern HeapOverflow_ <- (has _HeapOverflow -> True) where 833 HeapOverflow_ = review _HeapOverflow () 834#endif 835 836-- | This 'Exception' is raised by another thread calling 837-- 'Control.Concurrent.killThread', or by the system if it needs to terminate 838-- the thread for some reason. 839-- 840-- @ 841-- '_ThreadKilled' :: 'Prism'' 'AsyncException' () 842-- '_ThreadKilled' :: 'Prism'' 'SomeException' () 843-- @ 844_ThreadKilled :: AsAsyncException t => Prism' t () 845_ThreadKilled = _AsyncException . dimap seta (either id id) . right' . rmap (ThreadKilled <$) where 846 seta ThreadKilled = Right () 847 seta t = Left (pure t) 848{-# INLINE _ThreadKilled #-} 849 850#if __GLASGOW_HASKELL__ >= 710 851pattern ThreadKilled_ <- (has _ThreadKilled -> True) where 852 ThreadKilled_ = review _ThreadKilled () 853#endif 854 855-- | This 'Exception' is raised by default in the main thread of the program when 856-- the user requests to terminate the program via the usual mechanism(s) 857-- (/e.g./ Control-C in the console). 858-- 859-- @ 860-- '_UserInterrupt' :: 'Prism'' 'AsyncException' () 861-- '_UserInterrupt' :: 'Prism'' 'SomeException' () 862-- @ 863_UserInterrupt :: AsAsyncException t => Prism' t () 864_UserInterrupt = _AsyncException . dimap seta (either id id) . right' . rmap (UserInterrupt <$) where 865 seta UserInterrupt = Right () 866 seta t = Left (pure t) 867{-# INLINE _UserInterrupt #-} 868 869#if __GLASGOW_HASKELL__ >= 710 870pattern UserInterrupt_ <- (has _UserInterrupt -> True) where 871 UserInterrupt_ = review _UserInterrupt () 872#endif 873 874---------------------------------------------------------------------------- 875-- AsyncException 876---------------------------------------------------------------------------- 877 878-- | Thrown when the runtime system detects that the computation is guaranteed 879-- not to terminate. Note that there is no guarantee that the runtime system 880-- will notice whether any given computation is guaranteed to terminate or not. 881class AsNonTermination t where 882 -- | 883 -- @ 884 -- '__NonTermination' :: 'Prism'' 'NonTermination' 'NonTermination' 885 -- '__NonTermination' :: 'Prism'' 'SomeException' 'NonTermination' 886 -- @ 887 __NonTermination :: Prism' t NonTermination 888 889 -- | There is no additional information carried in a 'NonTermination' 'Exception'. 890 -- 891 -- @ 892 -- '_NonTermination' :: 'Prism'' 'NonTermination' () 893 -- '_NonTermination' :: 'Prism'' 'SomeException' () 894 -- @ 895 _NonTermination :: Prism' t () 896 _NonTermination = __NonTermination._NonTermination 897 {-# INLINE _NonTermination #-} 898 899instance AsNonTermination NonTermination where 900 __NonTermination = id 901 {-# INLINE __NonTermination #-} 902 903 _NonTermination = trivial NonTermination 904 {-# INLINE _NonTermination #-} 905 906instance AsNonTermination SomeException where 907 __NonTermination = exception 908 {-# INLINE __NonTermination #-} 909 910#if __GLASGOW_HASKELL__ >= 710 911pattern NonTermination__ e <- (preview __NonTermination -> Just e) where 912 NonTermination__ e = review __NonTermination e 913 914pattern NonTermination_ <- (has _NonTermination -> True) where 915 NonTermination_ = review _NonTermination () 916#endif 917 918---------------------------------------------------------------------------- 919-- NestedAtomically 920---------------------------------------------------------------------------- 921 922-- | Thrown when the program attempts to call atomically, from the 923-- 'Control.Monad.STM' package, inside another call to atomically. 924class AsNestedAtomically t where 925 -- | 926 -- @ 927 -- '__NestedAtomically' :: 'Prism'' 'NestedAtomically' 'NestedAtomically' 928 -- '__NestedAtomically' :: 'Prism'' 'SomeException' 'NestedAtomically' 929 -- @ 930 __NestedAtomically :: Prism' t NestedAtomically 931 932 -- | There is no additional information carried in a 'NestedAtomically' 'Exception'. 933 -- 934 -- @ 935 -- '_NestedAtomically' :: 'Prism'' 'NestedAtomically' () 936 -- '_NestedAtomically' :: 'Prism'' 'SomeException' () 937 -- @ 938 _NestedAtomically :: Prism' t () 939 _NestedAtomically = __NestedAtomically._NestedAtomically 940 {-# INLINE _NestedAtomically #-} 941 942instance AsNestedAtomically NestedAtomically where 943 __NestedAtomically = id 944 {-# INLINE __NestedAtomically #-} 945 946 _NestedAtomically = trivial NestedAtomically 947 {-# INLINE _NestedAtomically #-} 948 949instance AsNestedAtomically SomeException where 950 __NestedAtomically = exception 951 {-# INLINE __NestedAtomically #-} 952 953#if __GLASGOW_HASKELL__ >= 710 954pattern NestedAtomically__ e <- (preview __NestedAtomically -> Just e) where 955 NestedAtomically__ e = review __NestedAtomically e 956 957pattern NestedAtomically_ <- (has _NestedAtomically -> True) where 958 NestedAtomically_ = review _NestedAtomically () 959#endif 960 961---------------------------------------------------------------------------- 962-- BlockedIndefinitelyOnMVar 963---------------------------------------------------------------------------- 964 965-- | The thread is blocked on an 'Control.Concurrent.MVar.MVar', but there 966-- are no other references to the 'Control.Concurrent.MVar.MVar' so it can't 967-- ever continue. 968class AsBlockedIndefinitelyOnMVar t where 969 -- | 970 -- @ 971 -- '__BlockedIndefinitelyOnMVar' :: 'Prism'' 'BlockedIndefinitelyOnMVar' 'BlockedIndefinitelyOnMVar' 972 -- '__BlockedIndefinitelyOnMVar' :: 'Prism'' 'SomeException' 'BlockedIndefinitelyOnMVar' 973 -- @ 974 __BlockedIndefinitelyOnMVar :: Prism' t BlockedIndefinitelyOnMVar 975 976 -- | There is no additional information carried in a 'BlockedIndefinitelyOnMVar' 'Exception'. 977 -- 978 -- @ 979 -- '_BlockedIndefinitelyOnMVar' :: 'Prism'' 'BlockedIndefinitelyOnMVar' () 980 -- '_BlockedIndefinitelyOnMVar' :: 'Prism'' 'SomeException' () 981 -- @ 982 _BlockedIndefinitelyOnMVar :: Prism' t () 983 _BlockedIndefinitelyOnMVar = __BlockedIndefinitelyOnMVar._BlockedIndefinitelyOnMVar 984 {-# INLINE _BlockedIndefinitelyOnMVar #-} 985 986instance AsBlockedIndefinitelyOnMVar BlockedIndefinitelyOnMVar where 987 __BlockedIndefinitelyOnMVar = id 988 {-# INLINE __BlockedIndefinitelyOnMVar #-} 989 990 _BlockedIndefinitelyOnMVar = trivial BlockedIndefinitelyOnMVar 991 {-# INLINE _BlockedIndefinitelyOnMVar #-} 992 993instance AsBlockedIndefinitelyOnMVar SomeException where 994 __BlockedIndefinitelyOnMVar = exception 995 {-# INLINE __BlockedIndefinitelyOnMVar #-} 996 997#if __GLASGOW_HASKELL__ >= 710 998pattern BlockedIndefinitelyOnMVar__ e <- (preview __BlockedIndefinitelyOnMVar -> Just e) where 999 BlockedIndefinitelyOnMVar__ e = review __BlockedIndefinitelyOnMVar e 1000 1001pattern BlockedIndefinitelyOnMVar_ <- (has _BlockedIndefinitelyOnMVar -> True) where 1002 BlockedIndefinitelyOnMVar_ = review _BlockedIndefinitelyOnMVar () 1003#endif 1004 1005---------------------------------------------------------------------------- 1006-- BlockedIndefinitelyOnSTM 1007---------------------------------------------------------------------------- 1008 1009-- | The thread is waiting to retry an 'Control.Monad.STM.STM' transaction, 1010-- but there are no other references to any TVars involved, so it can't ever 1011-- continue. 1012class AsBlockedIndefinitelyOnSTM t where 1013 -- | 1014 -- @ 1015 -- '__BlockedIndefinitelyOnSTM' :: 'Prism'' 'BlockedIndefinitelyOnSTM' 'BlockedIndefinitelyOnSTM' 1016 -- '__BlockedIndefinitelyOnSTM' :: 'Prism'' 'SomeException' 'BlockedIndefinitelyOnSTM' 1017 -- @ 1018 __BlockedIndefinitelyOnSTM :: Prism' t BlockedIndefinitelyOnSTM 1019 1020 -- | There is no additional information carried in a 'BlockedIndefinitelyOnSTM' 'Exception'. 1021 -- 1022 -- @ 1023 -- '_BlockedIndefinitelyOnSTM' :: 'Prism'' 'BlockedIndefinitelyOnSTM' () 1024 -- '_BlockedIndefinitelyOnSTM' :: 'Prism'' 'SomeException' () 1025 -- @ 1026 _BlockedIndefinitelyOnSTM :: Prism' t () 1027 _BlockedIndefinitelyOnSTM = __BlockedIndefinitelyOnSTM._BlockedIndefinitelyOnSTM 1028 {-# INLINE _BlockedIndefinitelyOnSTM #-} 1029 1030instance AsBlockedIndefinitelyOnSTM BlockedIndefinitelyOnSTM where 1031 __BlockedIndefinitelyOnSTM = id 1032 {-# INLINE __BlockedIndefinitelyOnSTM #-} 1033 1034 _BlockedIndefinitelyOnSTM = trivial BlockedIndefinitelyOnSTM 1035 {-# INLINE _BlockedIndefinitelyOnSTM #-} 1036 1037instance AsBlockedIndefinitelyOnSTM SomeException where 1038 __BlockedIndefinitelyOnSTM = exception 1039 {-# INLINE __BlockedIndefinitelyOnSTM #-} 1040 1041#if __GLASGOW_HASKELL__ >= 710 1042pattern BlockedIndefinitelyOnSTM__ e <- (preview __BlockedIndefinitelyOnSTM -> Just e) where 1043 BlockedIndefinitelyOnSTM__ e = review __BlockedIndefinitelyOnSTM e 1044 1045pattern BlockedIndefinitelyOnSTM_ <- (has _BlockedIndefinitelyOnSTM -> True) where 1046 BlockedIndefinitelyOnSTM_ = review _BlockedIndefinitelyOnSTM () 1047#endif 1048 1049---------------------------------------------------------------------------- 1050-- Deadlock 1051---------------------------------------------------------------------------- 1052 1053-- | There are no runnable threads, so the program is deadlocked. The 1054-- 'Deadlock' 'Exception' is raised in the main thread only. 1055class AsDeadlock t where 1056 -- | 1057 -- @ 1058 -- '__Deadlock' :: 'Prism'' 'Deadlock' 'Deadlock' 1059 -- '__Deadlock' :: 'Prism'' 'SomeException' 'Deadlock' 1060 -- @ 1061 __Deadlock :: Prism' t Deadlock 1062 1063 -- | There is no information carried in a 'Deadlock' 'Exception'. 1064 -- 1065 -- @ 1066 -- '_Deadlock' :: 'Prism'' 'Deadlock' () 1067 -- '_Deadlock' :: 'Prism'' 'SomeException' () 1068 -- @ 1069 _Deadlock :: Prism' t () 1070 _Deadlock = __Deadlock._Deadlock 1071 {-# INLINE _Deadlock #-} 1072 1073instance AsDeadlock Deadlock where 1074 __Deadlock = id 1075 {-# INLINE __Deadlock #-} 1076 1077 _Deadlock = trivial Deadlock 1078 {-# INLINE _Deadlock #-} 1079 1080instance AsDeadlock SomeException where 1081 __Deadlock = exception 1082 {-# INLINE __Deadlock #-} 1083 1084#if __GLASGOW_HASKELL__ >= 710 1085pattern Deadlock__ e <- (preview __Deadlock -> Just e) where 1086 Deadlock__ e = review __Deadlock e 1087 1088pattern Deadlock_ <- (has _Deadlock -> True) where 1089 Deadlock_ = review _Deadlock () 1090#endif 1091 1092---------------------------------------------------------------------------- 1093-- NoMethodError 1094---------------------------------------------------------------------------- 1095 1096-- | A class method without a definition (neither a default definition, 1097-- nor a definition in the appropriate instance) was called. 1098class AsNoMethodError t where 1099 -- | 1100 -- @ 1101 -- '__NoMethodError' :: 'Prism'' 'NoMethodError' 'NoMethodError' 1102 -- '__NoMethodError' :: 'Prism'' 'SomeException' 'NoMethodError' 1103 -- @ 1104 __NoMethodError :: Prism' t NoMethodError 1105 1106 -- | Extract a description of the missing method. 1107 -- 1108 -- @ 1109 -- '_NoMethodError' :: 'Prism'' 'NoMethodError' 'String' 1110 -- '_NoMethodError' :: 'Prism'' 'SomeException' 'String' 1111 -- @ 1112 _NoMethodError :: Prism' t String 1113 _NoMethodError = __NoMethodError._NoMethodError 1114 {-# INLINE _NoMethodError #-} 1115 1116instance AsNoMethodError NoMethodError where 1117 __NoMethodError = id 1118 {-# INLINE __NoMethodError #-} 1119 1120 _NoMethodError = _Wrapping NoMethodError 1121 {-# INLINE _NoMethodError #-} 1122 1123instance AsNoMethodError SomeException where 1124 __NoMethodError = exception 1125 {-# INLINE __NoMethodError #-} 1126 1127#if __GLASGOW_HASKELL__ >= 710 1128pattern NoMethodError__ e <- (preview __NoMethodError -> Just e) where 1129 NoMethodError__ e = review __NoMethodError e 1130 1131pattern NoMethodError_ e <- (preview _NoMethodError -> Just e) where 1132 NoMethodError_ e = review _NoMethodError e 1133#endif 1134 1135---------------------------------------------------------------------------- 1136-- PatternMatchFail 1137---------------------------------------------------------------------------- 1138 1139-- | A pattern match failed. 1140class AsPatternMatchFail t where 1141 -- | 1142 -- @ 1143 -- '__PatternMatchFail' :: 'Prism'' 'PatternMatchFail' 'PatternMatchFail' 1144 -- '__PatternMatchFail' :: 'Prism'' 'SomeException' 'PatternMatchFail' 1145 -- @ 1146 __PatternMatchFail :: Prism' t PatternMatchFail 1147 1148 -- | Information about the source location of the pattern. 1149 -- 1150 -- @ 1151 -- '_PatternMatchFail' :: 'Prism'' 'PatternMatchFail' 'String' 1152 -- '_PatternMatchFail' :: 'Prism'' 'SomeException' 'String' 1153 -- @ 1154 _PatternMatchFail :: Prism' t String 1155 _PatternMatchFail = __PatternMatchFail._PatternMatchFail 1156 {-# INLINE _PatternMatchFail #-} 1157 1158instance AsPatternMatchFail PatternMatchFail where 1159 __PatternMatchFail = id 1160 {-# INLINE __PatternMatchFail #-} 1161 1162 _PatternMatchFail = _Wrapping PatternMatchFail 1163 {-# INLINE _PatternMatchFail #-} 1164 1165instance AsPatternMatchFail SomeException where 1166 __PatternMatchFail = exception 1167 {-# INLINE __PatternMatchFail #-} 1168 1169#if __GLASGOW_HASKELL__ >= 710 1170pattern PatternMatchFail__ e <- (preview __PatternMatchFail -> Just e) where 1171 PatternMatchFail__ e = review __PatternMatchFail e 1172 1173pattern PatternMatchFail_ e <- (preview _PatternMatchFail -> Just e) where 1174 PatternMatchFail_ e = review _PatternMatchFail e 1175#endif 1176 1177---------------------------------------------------------------------------- 1178-- RecConError 1179---------------------------------------------------------------------------- 1180 1181-- | An uninitialised record field was used. 1182class AsRecConError t where 1183 -- | 1184 -- @ 1185 -- '__RecConError' :: 'Prism'' 'RecConError' 'RecConError' 1186 -- '__RecConError' :: 'Prism'' 'SomeException' 'RecConError' 1187 -- @ 1188 __RecConError :: Prism' t RecConError 1189 1190 -- | Information about the source location where the record was 1191 -- constructed. 1192 -- 1193 -- @ 1194 -- '_RecConError' :: 'Prism'' 'RecConError' 'String' 1195 -- '_RecConError' :: 'Prism'' 'SomeException' 'String' 1196 -- @ 1197 _RecConError :: Prism' t String 1198 _RecConError = __RecConError._RecConError 1199 {-# INLINE _RecConError #-} 1200 1201instance AsRecConError RecConError where 1202 __RecConError = id 1203 {-# INLINE __RecConError #-} 1204 1205 _RecConError = _Wrapping RecConError 1206 {-# INLINE _RecConError #-} 1207 1208instance AsRecConError SomeException where 1209 __RecConError = exception 1210 {-# INLINE __RecConError #-} 1211 1212#if __GLASGOW_HASKELL__ >= 710 1213pattern RecConError__ e <- (preview __RecConError -> Just e) where 1214 RecConError__ e = review __RecConError e 1215 1216pattern RecConError_ e <- (preview _RecConError -> Just e) where 1217 RecConError_ e = review _RecConError e 1218#endif 1219 1220---------------------------------------------------------------------------- 1221-- RecSelError 1222---------------------------------------------------------------------------- 1223 1224-- | A record selector was applied to a constructor without the appropriate 1225-- field. This can only happen with a datatype with multiple constructors, 1226-- where some fields are in one constructor but not another. 1227class AsRecSelError t where 1228 -- | 1229 -- @ 1230 -- '__RecSelError' :: 'Prism'' 'RecSelError' 'RecSelError' 1231 -- '__RecSelError' :: 'Prism'' 'SomeException' 'RecSelError' 1232 -- @ 1233 __RecSelError :: Prism' t RecSelError 1234 1235 -- | Information about the source location where the record selection occurred. 1236 -- 1237 -- @ 1238 -- '_RecSelError' :: 'Prism'' 'RecSelError' 'String' 1239 -- '_RecSelError' :: 'Prism'' 'SomeException' 'String' 1240 -- @ 1241 _RecSelError :: Prism' t String 1242 _RecSelError = __RecSelError._RecSelError 1243 {-# INLINE _RecSelError #-} 1244 1245instance AsRecSelError RecSelError where 1246 __RecSelError = id 1247 {-# INLINE __RecSelError #-} 1248 1249 _RecSelError = _Wrapping RecSelError 1250 {-# INLINE _RecSelError #-} 1251 1252instance AsRecSelError SomeException where 1253 __RecSelError = exception 1254 {-# INLINE __RecSelError #-} 1255 1256#if __GLASGOW_HASKELL__ >= 710 1257pattern RecSelError__ e <- (preview __RecSelError -> Just e) where 1258 RecSelError__ e = review __RecSelError e 1259 1260pattern RecSelError_ e <- (preview _RecSelError -> Just e) where 1261 RecSelError_ e = review _RecSelError e 1262#endif 1263 1264---------------------------------------------------------------------------- 1265-- RecUpdError 1266---------------------------------------------------------------------------- 1267 1268-- | A record update was performed on a constructor without the 1269-- appropriate field. This can only happen with a datatype with multiple 1270-- constructors, where some fields are in one constructor but not another. 1271class AsRecUpdError t where 1272 -- | 1273 -- @ 1274 -- '__RecUpdError' :: 'Prism'' 'RecUpdError' 'RecUpdError' 1275 -- '__RecUpdError' :: 'Prism'' 'SomeException' 'RecUpdError' 1276 -- @ 1277 __RecUpdError :: Prism' t RecUpdError 1278 1279 -- | Information about the source location where the record was updated. 1280 -- 1281 -- @ 1282 -- '_RecUpdError' :: 'Prism'' 'RecUpdError' 'String' 1283 -- '_RecUpdError' :: 'Prism'' 'SomeException' 'String' 1284 -- @ 1285 _RecUpdError :: Prism' t String 1286 _RecUpdError = __RecUpdError._RecUpdError 1287 {-# INLINE _RecUpdError #-} 1288 1289instance AsRecUpdError RecUpdError where 1290 __RecUpdError = id 1291 {-# INLINE __RecUpdError #-} 1292 1293 _RecUpdError = _Wrapping RecUpdError 1294 {-# INLINE _RecUpdError #-} 1295 1296instance AsRecUpdError SomeException where 1297 __RecUpdError = exception 1298 {-# INLINE __RecUpdError #-} 1299 1300#if __GLASGOW_HASKELL__ >= 710 1301pattern RecUpdError__ e <- (preview __RecUpdError -> Just e) where 1302 RecUpdError__ e = review __RecUpdError e 1303 1304pattern RecUpdError_ e <- (preview _RecUpdError -> Just e) where 1305 RecUpdError_ e = review _RecUpdError e 1306#endif 1307 1308---------------------------------------------------------------------------- 1309-- ErrorCall 1310---------------------------------------------------------------------------- 1311 1312-- | This is thrown when the user calls 'Prelude.error'. 1313class AsErrorCall t where 1314 -- | 1315 -- @ 1316 -- '__ErrorCall' :: 'Prism'' 'ErrorCall' 'ErrorCall' 1317 -- '__ErrorCall' :: 'Prism'' 'SomeException' 'ErrorCall' 1318 -- @ 1319 __ErrorCall :: Prism' t ErrorCall 1320 1321 -- | Retrieve the argument given to 'Prelude.error'. 1322 -- 1323 -- 'ErrorCall' is isomorphic to a 'String'. 1324 -- 1325 -- >>> catching _ErrorCall (error "touch down!") return 1326 -- "touch down!" 1327 -- 1328 -- @ 1329 -- '_ErrorCall' :: 'Prism'' 'ErrorCall' 'String' 1330 -- '_ErrorCall' :: 'Prism'' 'SomeException' 'String' 1331 -- @ 1332 _ErrorCall :: Prism' t String 1333 _ErrorCall = __ErrorCall._ErrorCall 1334 {-# INLINE _ErrorCall #-} 1335 1336instance AsErrorCall ErrorCall where 1337 __ErrorCall = id 1338 {-# INLINE __ErrorCall #-} 1339 1340 _ErrorCall = _Wrapping ErrorCall 1341 {-# INLINE _ErrorCall #-} 1342 1343instance AsErrorCall SomeException where 1344 __ErrorCall = exception 1345 {-# INLINE __ErrorCall #-} 1346 1347#if __GLASGOW_HASKELL__ >= 710 1348pattern ErrorCall__ e <- (preview __ErrorCall -> Just e) where 1349 ErrorCall__ e = review __ErrorCall e 1350 1351pattern ErrorCall_ e <- (preview _ErrorCall -> Just e) where 1352 ErrorCall_ e = review _ErrorCall e 1353#endif 1354 1355#if MIN_VERSION_base(4,8,0) 1356---------------------------------------------------------------------------- 1357-- AllocationLimitExceeded 1358---------------------------------------------------------------------------- 1359 1360-- | This thread has exceeded its allocation limit. 1361class AsAllocationLimitExceeded t where 1362 -- | 1363 -- @ 1364 -- '__AllocationLimitExceeded' :: 'Prism'' 'AllocationLimitExceeded' 'AllocationLimitExceeded' 1365 -- '__AllocationLimitExceeded' :: 'Prism'' 'SomeException' 'AllocationLimitExceeded' 1366 -- @ 1367 __AllocationLimitExceeded :: Prism' t AllocationLimitExceeded 1368 1369 -- | There is no additional information carried in an 1370 -- 'AllocationLimitExceeded' 'Exception'. 1371 -- 1372 -- @ 1373 -- '_AllocationLimitExceeded' :: 'Prism'' 'AllocationLimitExceeded' () 1374 -- '_AllocationLimitExceeded' :: 'Prism'' 'SomeException' () 1375 -- @ 1376 _AllocationLimitExceeded :: Prism' t () 1377 _AllocationLimitExceeded = __AllocationLimitExceeded._AllocationLimitExceeded 1378 {-# INLINE _AllocationLimitExceeded #-} 1379 1380instance AsAllocationLimitExceeded AllocationLimitExceeded where 1381 __AllocationLimitExceeded = id 1382 {-# INLINE __AllocationLimitExceeded #-} 1383 1384 _AllocationLimitExceeded = trivial AllocationLimitExceeded 1385 {-# INLINE _AllocationLimitExceeded #-} 1386 1387instance AsAllocationLimitExceeded SomeException where 1388 __AllocationLimitExceeded = exception 1389 {-# INLINE __AllocationLimitExceeded #-} 1390 1391pattern AllocationLimitExceeded__ e <- (preview __AllocationLimitExceeded -> Just e) where 1392 AllocationLimitExceeded__ e = review __AllocationLimitExceeded e 1393 1394pattern AllocationLimitExceeded_ <- (has _AllocationLimitExceeded -> True) where 1395 AllocationLimitExceeded_ = review _AllocationLimitExceeded () 1396#endif 1397 1398#if MIN_VERSION_base(4,9,0) 1399---------------------------------------------------------------------------- 1400-- TypeError 1401---------------------------------------------------------------------------- 1402 1403-- | An expression that didn't typecheck during compile time was called. 1404-- This is only possible with @-fdefer-type-errors@. 1405class AsTypeError t where 1406 -- | 1407 -- @ 1408 -- '__TypeError' :: 'Prism'' 'TypeError' 'TypeError' 1409 -- '__TypeError' :: 'Prism'' 'SomeException' 'TypeError' 1410 -- @ 1411 __TypeError :: Prism' t TypeError 1412 1413 -- | Details about the failed type check. 1414 -- 1415 -- @ 1416 -- '_TypeError' :: 'Prism'' 'TypeError' 'String' 1417 -- '_TypeError' :: 'Prism'' 'SomeException' 'String' 1418 -- @ 1419 _TypeError :: Prism' t String 1420 _TypeError = __TypeError._TypeError 1421 {-# INLINE _TypeError #-} 1422 1423instance AsTypeError TypeError where 1424 __TypeError = id 1425 {-# INLINE __TypeError #-} 1426 1427 _TypeError = _Wrapping TypeError 1428 {-# INLINE _TypeError #-} 1429 1430instance AsTypeError SomeException where 1431 __TypeError = exception 1432 {-# INLINE __TypeError #-} 1433 1434pattern TypeError__ e <- (preview __TypeError -> Just e) where 1435 TypeError__ e = review __TypeError e 1436 1437pattern TypeError_ e <- (preview _TypeError -> Just e) where 1438 TypeError_ e = review _TypeError e 1439#endif 1440 1441#if MIN_VERSION_base(4,10,0) 1442---------------------------------------------------------------------------- 1443-- CompactionFailed 1444---------------------------------------------------------------------------- 1445 1446-- | Compaction found an object that cannot be compacted. 1447-- Functions cannot be compacted, nor can mutable objects or pinned objects. 1448class AsCompactionFailed t where 1449 -- | 1450 -- @ 1451 -- '__CompactionFailed' :: 'Prism'' 'CompactionFailed' 'CompactionFailed' 1452 -- '__CompactionFailed' :: 'Prism'' 'SomeException' 'CompactionFailed' 1453 -- @ 1454 __CompactionFailed :: Prism' t CompactionFailed 1455 1456 -- | Information about why a compaction failed. 1457 -- 1458 -- @ 1459 -- '_CompactionFailed' :: 'Prism'' 'CompactionFailed' 'String' 1460 -- '_CompactionFailed' :: 'Prism'' 'SomeException' 'String' 1461 -- @ 1462 _CompactionFailed :: Prism' t String 1463 _CompactionFailed = __CompactionFailed._CompactionFailed 1464 {-# INLINE _CompactionFailed #-} 1465 1466instance AsCompactionFailed CompactionFailed where 1467 __CompactionFailed = id 1468 {-# INLINE __CompactionFailed #-} 1469 1470 _CompactionFailed = _Wrapping CompactionFailed 1471 {-# INLINE _CompactionFailed #-} 1472 1473instance AsCompactionFailed SomeException where 1474 __CompactionFailed = exception 1475 {-# INLINE __CompactionFailed #-} 1476 1477pattern CompactionFailed__ e <- (preview __CompactionFailed -> Just e) where 1478 CompactionFailed__ e = review __CompactionFailed e 1479 1480pattern CompactionFailed_ e <- (preview _CompactionFailed -> Just e) where 1481 CompactionFailed_ e = review _CompactionFailed e 1482#endif 1483 1484------------------------------------------------------------------------------ 1485-- HandlingException 1486------------------------------------------------------------------------------ 1487 1488-- | This 'Exception' is thrown by @lens@ when the user somehow manages to rethrow 1489-- an internal 'HandlingException'. 1490class AsHandlingException t where 1491 -- | 1492 -- @ 1493 -- '__HandlingException' :: 'Prism'' 'HandlingException' 'HandlingException' 1494 -- '__HandlingException' :: 'Prism'' 'SomeException' 'HandlingException' 1495 -- @ 1496 __HandlingException :: Prism' t HandlingException 1497 1498 -- | There is no information carried in a 'HandlingException'. 1499 -- 1500 -- @ 1501 -- '_HandlingException' :: 'Prism'' 'HandlingException' () 1502 -- '_HandlingException' :: 'Prism'' 'SomeException' () 1503 -- @ 1504 _HandlingException :: Prism' t () 1505 _HandlingException = __HandlingException._HandlingException 1506 {-# INLINE _HandlingException #-} 1507 1508instance AsHandlingException HandlingException where 1509 __HandlingException = id 1510 {-# INLINE __HandlingException #-} 1511 1512 _HandlingException = trivial HandlingException 1513 {-# INLINE _HandlingException #-} 1514 1515instance AsHandlingException SomeException where 1516 __HandlingException = exception 1517 {-# INLINE __HandlingException #-} 1518 1519#if __GLASGOW_HASKELL__ >= 710 1520pattern HandlingException__ e <- (preview __HandlingException -> Just e) where 1521 HandlingException__ e = review __HandlingException e 1522 1523pattern HandlingException_ <- (has _HandlingException -> True) where 1524 HandlingException_ = review _HandlingException () 1525#endif 1526 1527------------------------------------------------------------------------------ 1528-- Helper Functions 1529------------------------------------------------------------------------------ 1530 1531trivial :: t -> Iso' t () 1532trivial t = const () `iso` const t 1533 1534