packages feed

ether 0.1.0.1 → 0.2.0.0

raw patch · 9 files changed

+84/−61 lines, 9 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Control.Ether.TH: deepN :: Int -> ExpQ -> ExpQ
- Control.Ether.TH: fmapN :: Int -> ExpQ
- Control.Monad.Ether.Implicit.Except.TH: try :: Int -> ExpQ
- Control.Monad.Ether.Implicit.Except.TH: try' :: Functor m => ExceptT e m a -> (e -> a) -> m a
+ Control.Monad.Ether: ethereal :: String -> String -> DecsQ
+ Control.Monad.Ether.Except: handle :: proxy tag -> (e -> a) -> Except tag e a -> a
+ Control.Monad.Ether.Except: handleT :: Functor m => proxy tag -> (e -> a) -> ExceptT tag e m a -> m a
+ Control.Monad.Ether.Implicit.Except: handle :: (e -> a) -> Except e a -> a
+ Control.Monad.Ether.Implicit.Except: handleT :: Functor m => (e -> a) -> ExceptT e m a -> m a

Files

CHANGELOG.md view
@@ -1,3 +1,12 @@+0.2.0.0+-------++* Convenience modules `Control.Monad.Ether` and `Control.Monad.Ether.Implicit`.+* Remove `fmapN` and `deepN`.+* Remove `Control.Monad.Ether.Implicit.Except.TH`.+* Add `handle` and `handleT`.++ 0.1.0.1 ------- 
ether.cabal view
@@ -1,5 +1,5 @@ name:                ether-version:             0.1.0.1+version:             0.2.0.0 synopsis:            Monad transformers and classes description:     Ether is a Haskell library that extends @mtl@ and @transformers@ with@@ -33,6 +33,7 @@                        Control.Monad.Trans.Ether.State.Lazy                        Control.Monad.Trans.Ether.State.Strict                        Control.Monad.Trans.Ether.Except+                       Control.Monad.Ether                        Control.Monad.Ether.Reader                        Control.Monad.Ether.Reader.Class                        Control.Monad.Ether.Writer@@ -43,13 +44,13 @@                        Control.Monad.Ether.State.Strict                        Control.Monad.Ether.Except                        Control.Monad.Ether.Except.Class+                       Control.Monad.Ether.Implicit                        Control.Monad.Ether.Implicit.Reader                        Control.Monad.Ether.Implicit.Writer                        Control.Monad.Ether.Implicit.State                        Control.Monad.Ether.Implicit.State.Lazy                        Control.Monad.Ether.Implicit.State.Strict                        Control.Monad.Ether.Implicit.Except-                       Control.Monad.Ether.Implicit.Except.TH    other-modules:       Control.Ether.Util 
src/Control/Ether/TH.hs view
@@ -1,11 +1,9 @@ {-# LANGUAGE TemplateHaskell #-} --- | Template haskell utilities.+-- | Template Haskell utilities.  module Control.Ether.TH     ( ethereal-    , fmapN-    , deepN     ) where  import qualified Language.Haskell.TH as TH@@ -40,19 +38,3 @@     tagDecl <- emptyDataDecl tagName     (tagProxySig, tagProxyVal) <- proxySimple tagProxyName tag     return [tagDecl, tagProxySig, tagProxyVal]---- |--- Compose 'fmap' @n@ times.------ @$('fmapN' 5) = fmap.fmap.fmap.fmap.fmap@-fmapN :: Int -> TH.ExpQ-fmapN 0 = [|id|]-fmapN n = TH.infixApp [|fmap|] [|(.)|] (fmapN (n - 1))---- |--- 'fmap' a function @n@ levels deep.------ @$('deepN' 3 [| f |]) = $('fmapN' 3) f ($('fmapN' 2) f ($('fmapN' 1) f id))@-deepN :: Int -> TH.ExpQ -> TH.ExpQ-deepN 0 _ = [|id|]-deepN n f = [| $(fmapN n) $f $(deepN (n-1) f) |]
+ src/Control/Monad/Ether.hs view
@@ -0,0 +1,23 @@++-- | This module provides convenience exports of all+-- tagged monad classes from Ether.++module Control.Monad.Ether+    ( module Control.Monad+    , module Control.Monad.Fix+    , module Control.Monad.Ether.Reader+    , module Control.Monad.Ether.Writer+    , module Control.Monad.Ether.State+    , module Control.Monad.Ether.Except+    , module Control.Ether.Wrapped+    , ethereal+    ) where++import Control.Monad+import Control.Monad.Fix+import Control.Monad.Ether.Reader+import Control.Monad.Ether.Writer+import Control.Monad.Ether.State+import Control.Monad.Ether.Except+import Control.Ether.Wrapped+import Control.Ether.TH (ethereal)
src/Control/Monad/Ether/Except.hs view
@@ -13,7 +13,19 @@     , exceptT     , runExceptT     , mapExceptT+    -- * Handle functions+    , handleT+    , handle     ) where  import Control.Monad.Ether.Except.Class import Control.Monad.Trans.Ether.Except hiding (throw, catch)+import Data.Functor.Identity (Identity(..))++-- | Runs an 'Except' and handles the exception with the given function.+handle :: proxy tag -> (e -> a) -> Except tag e a -> a+handle t h m = runIdentity (handleT t h m)++-- | Runs an 'ExceptT' and handles the exception with the given function.+handleT :: Functor m => proxy tag -> (e -> a) -> ExceptT tag e m a -> m a+handleT t h m = fmap (either h id) (runExceptT t m)
+ src/Control/Monad/Ether/Implicit.hs view
@@ -0,0 +1,19 @@++-- | This module provides convenience exports of all+-- implicitly tagged monad classes from Ether.++module Control.Monad.Ether.Implicit+    ( module Control.Monad+    , module Control.Monad.Fix+    , module Control.Monad.Ether.Implicit.Reader+    , module Control.Monad.Ether.Implicit.Writer+    , module Control.Monad.Ether.Implicit.State+    , module Control.Monad.Ether.Implicit.Except+    ) where++import Control.Monad+import Control.Monad.Fix+import Control.Monad.Ether.Implicit.Reader+import Control.Monad.Ether.Implicit.Writer+import Control.Monad.Ether.Implicit.State+import Control.Monad.Ether.Implicit.Except
src/Control/Monad/Ether/Implicit/Except.hs view
@@ -17,6 +17,9 @@     , exceptT     , runExceptT     , mapExceptT+    -- * Handle functions+    , handle+    , handleT     ) where  import Data.Proxy@@ -55,3 +58,11 @@ -- Note that due to implicit tagging the exception type cannot be changed. mapExceptT :: (m (Either e a) -> n (Either e b)) -> ExceptT e m a -> ExceptT e n b mapExceptT = Explicit.mapExceptT Proxy++-- | See 'Control.Monad.Ether.Except.handle'.+handle :: (e -> a) -> Except e a -> a+handle = Explicit.handle (Proxy :: Proxy e)++-- | See 'Control.Monad.Ether.Except.handleT'.+handleT :: Functor m => (e -> a) -> ExceptT e m a -> m a+handleT = Explicit.handleT (Proxy :: Proxy e)
− src/Control/Monad/Ether/Implicit/Except/TH.hs
@@ -1,22 +0,0 @@-{-# LANGUAGE TemplateHaskell #-}---- | Template Haskell utilities for exception handling.--module Control.Monad.Ether.Implicit.Except.TH (try', try) where--import qualified Language.Haskell.TH as TH-import Control.Ether.TH (deepN)-import Control.Monad.Ether.Implicit.Except---- | Basic building block for 'try'. Runs an 'ExceptT' with a handler.-try' :: Functor m => ExceptT e m a -> (e -> a) -> m a-try' m h = fmap (either h id) (runExceptT m)---- | Handle @n@ exceptions with supplied handlers.------ > $(try 3) monadicComputation--- >    (\Exception1 -> ...)--- >    (\Exception2 -> ...)--- >    (\Exception3 -> ...)-try :: Int -> TH.ExpQ-try n = deepN n [|try'|]
test/Regression.hs view
@@ -7,7 +7,6 @@ {-# LANGUAGE LambdaCase #-} module Main where -import Data.Functor.Identity import Data.Monoid import Control.Monad import Control.Ether.Tagged@@ -16,7 +15,6 @@ import Control.Monad.Ether.Reader import Control.Monad.Ether.State import Control.Monad.Ether.Writer-import Control.Monad.Ether.Implicit.Except.TH import qualified Control.Monad.Ether.Implicit.Reader as I import qualified Control.Monad.Ether.Implicit.State  as I import qualified Control.Monad.Ether.Implicit.Except as I@@ -167,24 +165,14 @@     T.when (d < 0) (I.throw (NegativeLog d))     return (log d) -try0 :: m a -> m a-try0 = $(try 0)--try1 :: Functor m => I.ExceptT e m a -> (e -> a) -> m a-try1 = $(try 1)--try2 :: Functor m => I.ExceptT e1 (I.ExceptT e2 m) a -> (e1 -> a) -> (e2 -> a) -> m a-try2 = $(try 2)--try3 :: Functor m => I.ExceptT e1 (I.ExceptT e2 (I.ExceptT e3 m)) a -> (e1 -> a) -> (e2 -> a) -> (e3 -> a) -> m a-try3 = $(try 3)+(&) :: a -> (a -> c) -> c+(&) = flip ($)  exceptCore' :: Double -> Double -> String-exceptCore' a b = runIdentity $ do-    $(try 2)-        (liftM show (exceptCore a b))-        (\(NegativeLog (x::Double)) -> "nl: " ++ show x)-        (\DivideByZero -> "dz")+exceptCore' a b = do+    liftM show (exceptCore a b)+    &I.handleT (\(NegativeLog (x::Double)) -> "nl: " ++ show x)+    &I.handle  (\DivideByZero -> "dz")  summatorCore     :: ( Num a