~ubuntu-branches/ubuntu/wily/agda/wily-proposed

« back to all changes in this revision

Viewing changes to src/full/Agda/Utils/Except.hs

  • Committer: Package Import Robot
  • Author(s): Iain Lane, d5cf60f
  • Date: 2015-05-20 13:08:33 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20150520130833-cdcmhagwsouna237
Tags: 2.4.2.2-2
[d5cf60f] Depend on ${shlibs:Depends}, to get libc (& maybe other) deps

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{-# LANGUAGE CPP                  #-}
 
2
{-# LANGUAGE FlexibleInstances    #-}
 
3
{-# LANGUAGE TypeSynonymInstances #-}
 
4
 
 
5
------------------------------------------------------------------------------
 
6
-- | Wrapper for Control.Monad.Except from the mtl package
 
7
------------------------------------------------------------------------------
 
8
 
 
9
module Agda.Utils.Except
 
10
  ( Error(noMsg, strMsg)
 
11
  , ExceptT
 
12
  , mkExceptT
 
13
  , MonadError(catchError, throwError)
 
14
  , runExceptT
 
15
  ) where
 
16
 
 
17
------------------------------------------------------------------------
 
18
#if MIN_VERSION_mtl(2,2,1)
 
19
-- New mtl, reexport ExceptT, define class Error for backward compat.
 
20
------------------------------------------------------------------------
 
21
 
 
22
import Control.Monad.Except
 
23
 
 
24
-- | We cannot define data constructors synonymous, so we define the
 
25
-- @mkExceptT@ function to be used instead of the data constructor
 
26
-- @ExceptT@.
 
27
mkExceptT :: m (Either e a) -> ExceptT e m a
 
28
mkExceptT = ExceptT
 
29
 
 
30
-- From Control.Monad.Trans.Error of transformers 0.3.0.0.
 
31
 
 
32
class Error a where
 
33
  noMsg  :: a
 
34
  strMsg :: String -> a
 
35
 
 
36
  noMsg    = strMsg ""
 
37
  strMsg _ = noMsg
 
38
 
 
39
-- | A string can be thrown as an error.
 
40
instance Error String where
 
41
    strMsg = id
 
42
 
 
43
------------------------------------------------------------------------
 
44
#else
 
45
-- Old mtl, need to define ExceptT from ErrorT
 
46
------------------------------------------------------------------------
 
47
 
 
48
import Control.Monad.Error
 
49
 
 
50
type ExceptT = ErrorT
 
51
 
 
52
-- | We cannot define data constructors synonymous, so we define the
 
53
-- @mkExceptT@ function to be used instead of the data constructor
 
54
-- @ErrorT@.
 
55
mkExceptT :: m (Either e a) -> ExceptT e m a
 
56
mkExceptT = ErrorT
 
57
 
 
58
-- | 'runExcept' function using mtl 2.1.*.
 
59
runExceptT ::  ExceptT e m a -> m (Either e a)
 
60
runExceptT = runErrorT
 
61
 
 
62
#endif