Skip to content

Commit 06ce5f2

Browse files
committed
Add a bunch of additional functionality to Control.Exception
1 parent bb7cd81 commit 06ce5f2

File tree

1 file changed

+87
-4
lines changed

1 file changed

+87
-4
lines changed

lib/base/Haskell/Control/Exception.agda

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ open import Haskell.Prim.Functor
77
open import Haskell.Prim.IO
88
open import Haskell.Prim.Maybe
99
open import Haskell.Prim.Monad
10+
open import Haskell.Prim.Ord
1011
open import Haskell.Prim.Show
1112
open import Haskell.Prim.String
1213

1314
open import Haskell.Extra.Dec
1415
open import Haskell.Extra.Refinement
1516

17+
private variable
18+
e1 e2 : Set
19+
1620
record Exception (e : Set) : Set where
1721
no-eta-equality
1822
field
@@ -28,17 +32,85 @@ postulate
2832
iEqIOException : Eq IOException
2933
iExceptionIOException : Exception IOException
3034

31-
postulate
32-
AssertionFailed : Set
33-
instance
34-
iExceptionAssertionFailed : Exception AssertionFailed
35+
data ArithException : Set where
36+
Overflow UnderFlow LossOfPrecision DivideByZero Denormal : ArithException
37+
RatioZeroDenominator : ArithException
38+
39+
postulate instance
40+
iOrdArithException : Ord ArithException
41+
iExceptionArithException : Exception ArithException
42+
43+
data ArrayException : Set where
44+
IndexOutOfBounds UndefinedElement : String ArrayException
45+
46+
postulate instance
47+
iOrdArrayException : Ord ArrayException
48+
iExceptionArrayException : Exception ArrayException
49+
50+
record AssertionFailed : Set where
51+
no-eta-equality; pattern
52+
field theFailedAssertion : String
53+
54+
postulate instance
55+
iExceptionAssertionFailed : Exception AssertionFailed
56+
57+
record NoMethodError : Set where
58+
no-eta-equality; pattern
59+
field theNoMethodError : String
60+
61+
postulate instance
62+
iExceptionNoMethodError : Exception NoMethodError
63+
64+
record PatternMatchFail : Set where
65+
no-eta-equality; pattern
66+
field thePatternMatchFail : String
67+
68+
postulate instance
69+
iExceptionPatternMatchFail : Exception PatternMatchFail
70+
71+
record RecConError : Set where
72+
no-eta-equality; pattern
73+
field theRecConError : String
74+
75+
postulate instance
76+
iExceptionRecConError : Exception RecConError
77+
78+
record RecSelError : Set where
79+
no-eta-equality; pattern
80+
field theRecSelError : String
81+
82+
postulate instance
83+
iExceptionRecSelError : Exception RecSelError
84+
85+
record RecUpdError : Set where
86+
no-eta-equality; pattern
87+
field theRecUpdError : String
88+
89+
postulate instance
90+
iExceptionRecUpdError : Exception RecUpdError
91+
92+
record ErrorCall : Set where
93+
no-eta-equality; pattern
94+
field theErrorCall : String
95+
96+
postulate instance
97+
iOrdErrorCall : Ord ErrorCall
98+
iExceptionErrorCall : Exception ErrorCall
99+
100+
record TypeError : Set where
101+
no-eta-equality; pattern
102+
field theTypeError : String
103+
104+
postulate instance
105+
iExceptionTypeError : Exception TypeError
35106

36107
postulate
37108
@0 MayThrow : Set Set
38109

39110
throw : {{Exception e}} @0 {{MayThrow e}} e a
40111
throwIO : {{Exception e}} @0 {{MayThrow e}} e IO a
41112

113+
postulate
42114
catch : {{Exception e}} (@0 {{MayThrow e}} IO a) (e IO a) IO a
43115
catchJust : {{Exception e}} (e Maybe b) (@0 {{MayThrow e}} IO a) (b IO a) IO a
44116

@@ -54,10 +126,21 @@ try a = catch (fmap Right a) (return ∘ Left)
54126
tryJust : {{Exception e}} (e Maybe b) (@0 {{MayThrow e}} IO a) IO (Either b a)
55127
tryJust p a = catchJust p (fmap Right a) (return ∘ Left)
56128

129+
postulate
130+
evaluate : a IO a
131+
mapException : {{Exception e1}} {{Exception e2}} (e1 e2) a a
132+
57133
assert : @0 {{MayThrow AssertionFailed}} (@0 b : Type ℓ) {{Dec b}} (@0 {{b}} a) a
58134
assert _ {{True ⟨ p ⟩}} x = x {{p}}
59135
assert _ {{False ⟨ _ ⟩}} x = throw oops
60136
where postulate oops : AssertionFailed
61137

138+
postulate
139+
bracket : IO a (a IO b) (a IO c) IO c
140+
bracket_ : IO a IO b IO c IO c
141+
bracketOnError : IO a (a IO b) (a IO c) IO c
142+
finally : IO a IO b IO a
143+
onException : IO a IO b IO a
144+
62145
ioException : @0 {{MayThrow IOException}} IOException IO a
63146
ioException = throwIO

0 commit comments

Comments
 (0)