on bfa39bf help sign in
Idris-dev/effects/Effect/Exception.idr
40 lines 921 B history raw
1module Effect.Exception
3import Effects
4import System
5import Control.IOExcept
7data Exception : Type -> Type -> Type -> Type -> Type where
8 Raise : a -> Exception a () () b
10instance Handler (Exception a) Maybe where
11 handle _ (Raise e) k = Nothing
13instance Show a => Handler (Exception a) IO where
14 handle _ (Raise e) k = do print e
15 believe_me (exit 1)
17instance Handler (Exception a) (IOExcept a) where
18 handle _ (Raise e) k = ioM (return (Left e))
20instance Handler (Exception a) (Either a) where
21 handle _ (Raise e) k = Left e
23EXCEPTION : Type -> EFFECT
24EXCEPTION t = MkEff () (Exception t)
26raise : a -> Eff m [EXCEPTION a] b
27raise err = Raise err
35-- TODO: Catching exceptions mid program?
36-- probably need to invoke a new interpreter
38-- possibly add a 'handle' to the Eff language so that an alternative
39-- handler can be introduced mid interpretation?