packages feed

transformers-abort (empty) → 0.1

raw patch · 4 files changed

+180/−0 lines, 4 filesdep +basedep +data-defaultdep +failuresetup-changed

Dependencies added: base, data-default, failure, monad-control, pointed, semigroupoids, transformers, transformers-base

Files

+ LICENSE view
@@ -0,0 +1,27 @@+Copyright (c) 2011, Mikhail Vorozhtsov+All rights reserved.++Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met:++- Redistributions of source code must retain the above copyright notice, +  this list of conditions and the following disclaimer.+- Redistributions in binary form must reproduce the above copyright +  notice, this list of conditions and the following disclaimer in the +  documentation and/or other materials provided with the distribution.+- Neither the names of the copyright owners nor the names of the +  contributors may be used to endorse or promote products derived +  from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Control/Monad/Trans/Abort.hs view
@@ -0,0 +1,111 @@+{-# LANGUAGE UnicodeSyntax #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE UndecidableInstances #-}++module Control.Monad.Trans.Abort (+    Abort,+    runAbort,+    runAbort',+    AbortT(..),+    runAbortT',+    abort,+    recover+  ) where++import Data.Pointed+import Data.Functor.Identity+import Data.Functor.Alt+import Data.Functor.Plus+import Data.Functor.Bind+import Data.Functor.Bind.Trans+import Data.Default+import Control.Applicative+import Control.Monad (ap, MonadPlus(..))+import Control.Monad.Base+import Control.Monad.Fix+import Control.Monad.Trans.Class+import Control.Monad.Trans.Control+import Control.Monad.IO.Class+import Control.Monad.IO.Control+import Control.Failure++newtype AbortT e μ α = AbortT { runAbortT ∷ μ (Either e α) }++type Abort e α = AbortT e Identity α++runAbort ∷ Abort e α → Either e α+runAbort = runIdentity . runAbortT++instance Monad μ ⇒ Pointed (AbortT e μ) where+  point = AbortT . return . Right++instance Functor μ ⇒ Functor (AbortT e μ) where+  fmap f = AbortT . fmap (fmap f) . runAbortT++instance (Functor μ, Monad μ) ⇒ Alt (AbortT e μ) where+  m <!> m' = recover m (const m')++instance (Functor μ, Monad μ, Default e) ⇒ Plus (AbortT e μ) where+  zero = mzero++instance (Functor μ, Monad μ) ⇒ Apply (AbortT e μ) where+  (<.>) = ap++instance (Functor μ, Monad μ) ⇒ Applicative (AbortT e μ) where+  pure  = return+  (<*>) = ap++instance (Functor μ, Monad μ, Default e) ⇒ Alternative (AbortT e μ) where+  empty = zero+  (<|>) = (<!>)++instance (Functor μ, Monad μ) ⇒ Bind (AbortT e μ) where+  (>>-) = (>>=)++instance Monad μ ⇒ Monad (AbortT e μ) where+  return  = AbortT . return . Right+  m >>= f = AbortT $ runAbortT m >>= either (return . Left) (runAbortT . f)+  fail    = AbortT . fail++instance (Monad μ, Default e) ⇒ MonadPlus (AbortT e μ) where+  mzero = abort def+  m `mplus` m' = recover m (const m')++instance MonadFix μ ⇒ MonadFix (AbortT e μ) where+  mfix f = AbortT $ mfix $+    runAbortT . f . either (error "mfix(AbortT): Left") id++instance MonadIO μ ⇒ MonadIO (AbortT e μ) where+  liftIO = lift . liftIO++instance MonadBase μ η ⇒ MonadBase (AbortT e μ) η where+  liftBase = lift . liftBase++instance BindTrans (AbortT e) where+  liftB = AbortT . fmap Right++instance MonadTrans (AbortT e) where+  lift = AbortT . ap (return Right)++instance MonadTransControl (AbortT e) where+  liftControl f = lift $ f $ (return . AbortT . return =<<) . runAbortT++instance MonadControlIO μ ⇒ MonadControlIO (AbortT e μ) where+  liftControlIO = liftLiftControlBase liftControlIO++instance Monad μ ⇒ Failure e (AbortT e μ) where+  failure = abort++runAbortT' ∷ Monad μ ⇒ AbortT α μ α → μ α+runAbortT' m = runAbortT m >>= return . either id id++runAbort' ∷ Abort α α → α+runAbort' = runIdentity . runAbortT'++abort ∷ Monad μ ⇒ e → AbortT e μ α+abort = AbortT . return . Left++recover ∷ Monad μ ⇒ AbortT e μ α → (e → AbortT e μ α) → AbortT e μ α+recover m h = AbortT $ runAbortT m >>= either (runAbortT . h) (return . Right)+
+ transformers-abort.cabal view
@@ -0,0 +1,40 @@+Name: transformers-abort+Version: 0.1+Category: Control+Stability: experimental+Synopsis: A better error monad transformer+Description:+  This package provides a better error monad transformer for+  the @transformers@ package.++Homepage: https://github.com/mvv/transformers-abort+Bug-Reports: https://github.com/mvv/transformers-abort/issues++Author: Mikhail Vorozhtsov <mikhail.vorozhtsov@gmail.com>+Maintainer: Mikhail Vorozhtsov <mikhail.vorozhtsov@gmail.com>+Copyright: 2011 Mikhail Vorozhtsov <mikhail.vorozhtsov@gmail.com>+License: BSD3+License-File: LICENSE++Cabal-Version: >= 1.6.0+Build-Type: Simple++Source-Repository head+  Type: git+  Location: https://github.com/mvv/transformers-abort.git++Library+  Build-Depends:+    base              >= 4 && < 5,+    transformers      >= 0.2,+    transformers-base >= 0.1,+    semigroupoids     >= 1.2,+    pointed           >= 2.0.1,+    data-default      >= 0.2,+    failure           >= 0.1,+    monad-control     >= 0.2.0.2+  Hs-Source-Dirs: src+  GHC-Options: -Wall+  Exposed-Modules:+    Control.Monad.Trans.Abort+