comonads-fd (empty) → 0.1.0
raw patch · 9 files changed
+360/−0 lines, 9 filesdep +basedep +comonaddep +comonad-transformerssetup-changed
Dependencies added: base, comonad, comonad-transformers, transformers
Files
- Control/Comonad/Env.hs +37/−0
- Control/Comonad/Env/Class.hs +55/−0
- Control/Comonad/Store.hs +31/−0
- Control/Comonad/Store/Class.hs +88/−0
- Control/Comonad/Traced.hs +29/−0
- Control/Comonad/Traced/Class.hs +52/−0
- LICENSE +30/−0
- Setup.lhs +7/−0
- comonads-fd.cabal +31/−0
+ Control/Comonad/Env.hs view
@@ -0,0 +1,37 @@+-----------------------------------------------------------------------------+-- |+-- Module : Control.Comonad.Env+-- Copyright : (C) 2008-2011 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : experimental+-- Portability : non-portable (fundeps, MPTCs)+--+-- The Env comonad (aka the Coreader, Environment, or Product comonad)+-- +-- A co-Kleisli arrow in the Env comonad is isomorphic to a Kleisli arrow+-- in the reader monad.+--+-- (a -> e -> m) ~ (a, e) -> m ~ Env e a -> m+----------------------------------------------------------------------------+module Control.Comonad.Env ( + -- * ComonadEnv class+ ComonadEnv(..)+ , asks+ -- * The Env comonad+ , Env+ , env+ , runEnv+ -- * The EnvT comonad transformer+ , EnvT(..)+ , runEnvT+ -- * Re-exported modules+ , module Control.Comonad+ , module Control.Comonad.Trans.Class+ ) where++import Control.Comonad+import Control.Comonad.Env.Class (ComonadEnv(..), asks)+import Control.Comonad.Trans.Class+import Control.Comonad.Trans.Env (Env, env, runEnv, EnvT(..), runEnvT)
+ Control/Comonad/Env/Class.hs view
@@ -0,0 +1,55 @@+{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances #-}+-----------------------------------------------------------------------------+-- |+-- Module : Control.Comonad.Env.Class+-- Copyright : (C) 2008-2011 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : experimental+-- Portability : non-portable (fundeps, MPTCs)+----------------------------------------------------------------------------+module Control.Comonad.Env.Class + ( ComonadEnv(..)+ , asks+ ) where++import Control.Comonad+import Control.Comonad.Trans.Class+import qualified Control.Comonad.Trans.Env as T+-- import qualified Control.Comonad.Trans.Pointer as P+import Control.Comonad.Trans.Store+import Control.Comonad.Trans.Discont+import Control.Comonad.Trans.Identity +-- import Data.Ix++class Comonad w => ComonadEnv e w | w -> e where+ ask :: w a -> e++asks :: ComonadEnv e w => (e -> e') -> w a -> e'+asks f wa = f (ask wa)+{-# INLINE asks #-}++instance Comonad w => ComonadEnv e (T.EnvT e w) where+ ask = T.ask++instance ComonadEnv e ((,)e) where+ ask = fst++lowerAsk :: (ComonadEnv e w, ComonadTrans t) => t w a -> e+lowerAsk = ask . lower+{-# INLINE lowerAsk #-}++-- All of these require UndecidableInstances because they do not satisfy the coverage condition++-- instance (ComonadEnv e w, Ix i) => ComonadEnv e (PointerT i w) where+-- ask = lowerAsk++instance ComonadEnv e w => ComonadEnv e (StoreT t w) where+ ask = lowerAsk++instance ComonadEnv e w => ComonadEnv e (DiscontT t w) where+ ask = lowerAsk++instance ComonadEnv e w => ComonadEnv e (IdentityT w) where+ ask = lowerAsk
+ Control/Comonad/Store.hs view
@@ -0,0 +1,31 @@+-----------------------------------------------------------------------------+-- |+-- Module : Control.Comonad.Store+-- Copyright : (C) 2008-2011 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : experimental+-- Portability : non-portable (fundeps, MPTCs)+----------------------------------------------------------------------------+module Control.Comonad.Store ( + -- * ComonadStore class+ ComonadStore(..)+ , gets+ , experiment+ -- * The Store comonad+ , Store+ , store+ , runStore+ -- * The StoreT comonad transformer+ , StoreT(..)+ , runStoreT+ -- * Re-exported modules+ , module Control.Comonad+ , module Control.Comonad.Trans.Class+ ) where++import Control.Comonad+import Control.Comonad.Store.Class (ComonadStore(..), gets, experiment)+import Control.Comonad.Trans.Class+import Control.Comonad.Trans.Store (Store, store, runStore, StoreT(..), runStoreT)
+ Control/Comonad/Store/Class.hs view
@@ -0,0 +1,88 @@+{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances #-}+-----------------------------------------------------------------------------+-- |+-- Module : Control.Comonad.Store.Class+-- Copyright : (C) 2008-2011 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : experimental+-- Portability : non-portable (fundeps, MPTCs)+----------------------------------------------------------------------------+module Control.Comonad.Store.Class + ( ComonadStore(..)+ , gets+ , experiment+ ) where++import Control.Comonad+import Control.Comonad.Trans.Class+import qualified Control.Comonad.Trans.Store as T+import Control.Comonad.Trans.Discont+import Control.Comonad.Trans.Env+import Control.Comonad.Trans.Identity +import Control.Comonad.Trans.Traced+import Data.Monoid+-- import qualified Control.Comonad.Trans.Pointer as P+-- import Data.Ix++class Comonad w => ComonadStore s w | w -> s where+ get :: w a -> s+ put :: s -> w a -> a+ modify :: (s -> s) -> w a -> a++ modify f wa = put (f (get wa)) wa++gets :: ComonadStore s w => (s -> t) -> w a -> t+gets f wa = f (get wa)+{-# INLINE gets #-}++experiment :: (ComonadStore s w, Functor f) => f (s -> s) -> w a -> f a+experiment ff wa = fmap (`modify` wa) ff+{-# INLINE experiment #-}++instance Comonad w => ComonadStore s (T.StoreT s w) where+ get = T.get+ put = T.put+ modify = T.modify++{-+instance (Comonad w, Ix i) => ComonadStore i (P.PointerT i w) where+ get = P.get+ put = P.put+ modify = P.modify+-}++-- All of these require UndecidableInstances because they do not satisfy the coverage condition++lowerGet :: (ComonadTrans t, ComonadStore s w) => t w a -> s+lowerGet = get . lower+{-# INLINE lowerGet #-}++lowerPut :: (ComonadTrans t, ComonadStore s w) => s -> t w a -> a+lowerPut s = put s . lower+{-# INLINE lowerPut #-}++lowerModify :: (ComonadTrans t, ComonadStore s w) => (s -> s) -> t w a -> a+lowerModify f = modify f . lower+{-# INLINE lowerModify #-}++instance ComonadStore s w => ComonadStore s (DiscontT k w) where+ get = lowerGet+ put = lowerPut+ modify = lowerModify++instance ComonadStore s w => ComonadStore s (IdentityT w) where+ get = lowerGet+ put = lowerPut+ modify = lowerModify++instance ComonadStore s w => ComonadStore s (EnvT e w) where+ get = lowerGet+ put = lowerPut+ modify = lowerModify++instance (ComonadStore s w, Monoid m) => ComonadStore s (TracedT m w) where+ get = lowerGet+ put = lowerPut+ modify = lowerModify
+ Control/Comonad/Traced.hs view
@@ -0,0 +1,29 @@+-----------------------------------------------------------------------------+-- |+-- Module : Control.Comonad.Traced+-- Copyright : (C) 2008-2011 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : experimental+-- Portability : non-portable (fundeps, MPTCs)+----------------------------------------------------------------------------+module Control.Comonad.Traced ( + -- * ComonadTraced class+ ComonadTraced(..)+ , traces+ -- * The Traced comonad+ , Traced+ , traced+ , runTraced+ -- * The TracedT comonad transformer+ , TracedT(..)+ -- * Re-exported modules+ , module Control.Comonad+ , module Control.Comonad.Trans.Class+ ) where++import Control.Comonad+import Control.Comonad.Traced.Class (ComonadTraced(..), traces)+import Control.Comonad.Trans.Class+import Control.Comonad.Trans.Traced (Traced, traced, runTraced, TracedT(..), runTracedT)
+ Control/Comonad/Traced/Class.hs view
@@ -0,0 +1,52 @@+{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances #-}+-----------------------------------------------------------------------------+-- |+-- Module : Control.Comonad.Traced.Class+-- Copyright : (C) 2008-2011 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : experimental+-- Portability : non-portable (fundeps, MPTCs)+----------------------------------------------------------------------------+module Control.Comonad.Traced.Class + ( ComonadTraced(..)+ , traces+ ) where++import Control.Comonad+import Control.Comonad.Trans.Class+import qualified Control.Comonad.Trans.Traced as T+import Control.Comonad.Trans.Discont+import Control.Comonad.Trans.Env+import Control.Comonad.Trans.Store+import Control.Comonad.Trans.Identity +import Data.Monoid++class Comonad w => ComonadTraced m w | w -> m where+ trace :: m -> w a -> a++traces :: ComonadTraced m w => (a -> m) -> w a -> a+traces f wa = trace (f (extract wa)) wa+{-# INLINE traces #-}++instance (Comonad w, Monoid m) => ComonadTraced m (T.TracedT m w) where+ trace = T.trace++lowerTrace :: (ComonadTrans t, ComonadTraced m w) => m -> t w a -> a+lowerTrace m = trace m . lower+{-# INLINE lowerTrace #-}++-- All of these require UndecidableInstances because they do not satisfy the coverage condition++instance ComonadTraced m w => ComonadTraced m (DiscontT k w) where+ trace = lowerTrace++instance ComonadTraced m w => ComonadTraced m (IdentityT w) where+ trace = lowerTrace++instance ComonadTraced m w => ComonadTraced m (EnvT e w) where+ trace = lowerTrace++instance ComonadTraced m w => ComonadTraced m (StoreT s w) where+ trace = lowerTrace
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright 2008-2011 Edward Kmett++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:++1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++2. 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.++3. Neither the name of the author nor the names of his contributors+ may be used to endorse or promote products derived from this software+ without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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.lhs view
@@ -0,0 +1,7 @@+#!/usr/bin/runhaskell+> module Main (main) where++> import Distribution.Simple++> main :: IO ()+> main = defaultMain
+ comonads-fd.cabal view
@@ -0,0 +1,31 @@+name: comonads-fd+category: Control, Comonads+version: 0.1.0+license: BSD3+cabal-version: >= 1.2+license-file: LICENSE+author: Edward A. Kmett+maintainer: Edward A. Kmett <ekmett@gmail.com>+stability: experimental+homepage: http://comonad.com/reader/+copyright: Copyright (C) 2008-2011 Edward A. Kmett+synopsis: Comonad transformers using functional dependencies.+description: Comonad transformers using functional dependencies.+build-type: Simple++library+ build-depends: + base > 4 && < 5,+ transformers >= 0.2.0 && < 0.3,+ comonad >= 0.1 && < 0.2,+ comonad-transformers >= 0.1 && < 0.2++ exposed-modules:+ Control.Comonad.Env+ Control.Comonad.Env.Class+ Control.Comonad.Store+ Control.Comonad.Store.Class+ Control.Comonad.Traced+ Control.Comonad.Traced.Class++ ghc-options: -Wall