@@ -7,12 +7,16 @@ open import Haskell.Prim.Functor
77open import Haskell.Prim.IO
88open import Haskell.Prim.Maybe
99open import Haskell.Prim.Monad
10+ open import Haskell.Prim.Ord
1011open import Haskell.Prim.Show
1112open import Haskell.Prim.String
1213
1314open import Haskell.Extra.Dec
1415open import Haskell.Extra.Refinement
1516
17+ private variable
18+ e1 e2 : Set
19+
1620record 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
36107postulate
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)
54126tryJust : {{Exception e}} → (e → Maybe b) → (@0 {{MayThrow e}} → IO a) → IO (Either b a)
55127tryJust 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+
57133assert : @0 {{MayThrow AssertionFailed}} → (@0 b : Type ℓ) → {{Dec b}} → (@0 {{b}} → a) → a
58134assert _ {{True ⟨ p ⟩}} x = x {{p}}
59135assert _ {{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+
62145ioException : @0 {{MayThrow IOException}} → IOException → IO a
63146ioException = throwIO
0 commit comments