File: Throws.hs

package info (click to toggle)
haskell-encoding 0.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,392 kB
  • sloc: haskell: 4,372; ansic: 11; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 766 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{-# LANGUAGE FlexibleInstances,MultiParamTypeClasses #-}
module Control.Throws where

import Control.Exception.Extensible
import Control.Monad.Identity
import Control.Monad.Reader
import Control.Monad.State

class Throws e m where
    throwException :: e -> m a

instance Exception e => Throws e Identity where
    throwException = throw

{-instance MonadError e m => Throws e m where
    throwException = throwError-}

instance Throws e (Either e) where
    throwException = Left

instance Exception e => Throws e IO where
    throwException = throw

instance Throws e m => Throws e (StateT s m) where
    throwException x = StateT (\s -> throwException x)

instance Throws e m => Throws e (ReaderT s m) where
    throwException x = ReaderT (\s -> throwException x)