packages feed

control-monad-attempt (empty) → 0.0.0

raw patch · 4 files changed

+117/−0 lines, 4 filesdep +attemptdep +basedep +sybsetup-changed

Dependencies added: attempt, base, syb, transformers

Files

+ Control/Monad/Attempt.hs view
@@ -0,0 +1,64 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+---------------------------------------------------------+--+-- Module        : Control.Monad.Attempt+-- Copyright     : Michael Snoyman+-- License       : BSD3+--+-- Maintainer    : Michael Snoyman <michael@snoyman.com>+-- Stability     : Unstable+-- Portability   : portable+--+---------------------------------------------------------++-- | Provide a monad transformer for the attempt monad, which allows the+-- reporting of errors using extensible exceptions.+module Control.Monad.Attempt+    ( AttemptT (..)+    , evalAttemptT+    , module Data.Attempt+    ) where++import Data.Attempt+import Control.Applicative+import Control.Monad+import Control.Monad.Trans+import Control.Exception (Exception)++newtype AttemptT m v = AttemptT {+    runAttemptT :: m (Attempt v)+}++instance Monad m => Functor (AttemptT m) where+    fmap f = AttemptT . liftM (liftM f) . runAttemptT+instance Monad m => Applicative (AttemptT m) where+    pure = return+    (<*>) = ap+instance Monad m => Monad (AttemptT m) where+    return = AttemptT . return . return+    (AttemptT mv) >>= f = AttemptT $ do+        v <- mv+        attempt (return . failure) (runAttemptT . f) v+instance (Exception e, Monad m) => Failure e (AttemptT m) where+    failure = AttemptT . return . failure+instance (Monad m, Exception e) => WrapFailure e (AttemptT m) where+    wrapFailure f (AttemptT mv) = AttemptT $ liftM (wrapFailure f) mv+instance MonadTrans AttemptT where+    lift = AttemptT . liftM return where+instance MonadIO m => MonadIO (AttemptT m) where+    liftIO = AttemptT . liftM return . liftIO where+instance Monad m => FromAttempt (AttemptT m) where+    fromAttempt = attempt failure return++-- | Instances of 'FromAttempt' specify a manner for embedding 'Attempt'+-- failures directly into the target data type. For example, the 'IO' instance+-- simply throws a runtime error. This is a convenience wrapper when you simply+-- want to use that default action.+--+-- So given a type 'AttemptT' 'IO' 'Int', this function will convert it to 'IO'+-- 'Int', throwing any exceptions in the original value.+evalAttemptT :: (Monad m, FromAttempt m)+             => AttemptT m v+             -> m v+evalAttemptT = join . liftM fromAttempt . runAttemptT where
+ LICENSE view
@@ -0,0 +1,25 @@+The following license covers this documentation, and the source code, except+where otherwise indicated.++Copyright 2008, Michael Snoyman. 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.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "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 HOLDERS 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.lhs view
@@ -0,0 +1,7 @@+#!/usr/bin/env runhaskell++> module Main where+> import Distribution.Simple++> main :: IO ()+> main = defaultMain
+ control-monad-attempt.cabal view
@@ -0,0 +1,21 @@+name:            control-monad-attempt+version:         0.0.0+license:         BSD3+license-file:    LICENSE+author:          Michael Snoyman, Nicolas Pouillard+maintainer:      Michael Snoyman <michael@snoyman.com>+synopsis:        Monad transformer for attempt.+description:     This package uses the transformers library.+category:        Data, Failure+stability:       stable+cabal-version:   >= 1.2+build-type:      Simple+homepage:        http://github.com/snoyberg/attempt/tree/transformer++library+    build-depends:   base >= 4 && < 5,+                     syb,+                     transformers >= 0.1.4.0,+                     attempt >= 0.2.0 && < 0.3+    exposed-modules: Control.Monad.Attempt+    ghc-options:     -Wall