packages feed

indexed-extras (empty) → 0.1

raw patch · 5 files changed

+347/−0 lines, 5 filesdep +basedep +bifunctorsdep +indexedsetup-changed

Dependencies added: base, bifunctors, indexed, mtl, pointed

Files

+ Control/Monad/Indexed/Cont.hs view
@@ -0,0 +1,114 @@+-------------------------------------------------------------------------------------------+-- |+-- Module	: Control.Monad.Indexed.Cont+-- Copyright 	: 2008 Edward Kmett, Dan Doel+-- License	: BSD+--+-- Maintainer	: Reiner Pope <reiner.pope@gmail.com>+-- Stability	: experimental+-- Portability	: rank-2 Types required for correctness of shift, but they can be removed+-------------------------------------------------------------------------------------------+module Control.Monad.Indexed.Cont +	( IxMonadCont(reset, shift)+	, IxContT(IxContT, runIxContT)+	, runIxContT_+	, IxCont(IxCont)+	, runIxCont+	, runIxCont_+	) where++import Control.Applicative+import Data.Pointed+-- import Control.Monad.Trans+import Control.Monad.Identity+import Control.Monad.Indexed+import Control.Monad.State+import Control.Monad.Reader+import Control.Monad.Indexed.Trans++class IxMonad m => IxMonadCont m where+	reset :: m a o o -> m r r a+	shift :: (forall i. (a -> m i i o) -> m r j j) -> m r o a+--	shift :: ((a -> m i i o) -> m r j j) -> m r o a++newtype IxContT m r o a = IxContT { runIxContT :: (a -> m o) -> m r }++runIxContT_ :: Monad m => IxContT m r a a -> m r +runIxContT_ m = runIxContT m return++instance IxFunctor (IxContT m) where+	imap f m = IxContT $ \c -> runIxContT m (c . f)++instance IxPointed (IxContT m) where+	ireturn a = IxContT ($a)++instance Monad m => IxApplicative (IxContT m) where+	iap = iapIxMonad++instance Monad m => IxMonad (IxContT m) where+	ibind f c = IxContT $ \k -> runIxContT c $ \a -> runIxContT (f a) k++instance Monad m => IxMonadCont (IxContT m) where+	reset e = IxContT $ \k -> runIxContT e return >>= k+	shift e = IxContT $ \k -> e (\a -> IxContT (\k' -> k a >>= k')) `runIxContT` return++instance Monad m => Functor (IxContT m i j) where+	fmap = imap++instance Monad m => Pointed (IxContT m i i) where+	point = ireturn++instance Monad m => Applicative (IxContT m i i) where+	pure = ireturn+	(<*>) = iap++instance Monad m => Monad (IxContT m i i) where+	return = ireturn+	m >>= k = ibind k m++--instance Monad m => MonadCont (IxContT m i i) where +--	callCC f = shift (\k -> f k >>>= k)++instance IxMonadTrans IxContT where+	ilift m = IxContT (m >>=)++instance MonadReader e m => MonadReader e (IxContT m i i) where+	ask = ilift ask+	local f m = IxContT $ \c -> do+		r <- ask+		local f (runIxContT m (local (const r) . c))++instance MonadState e m => MonadState e (IxContT m i i) where+	get = ilift get+	put = ilift . put++instance MonadIO m => MonadIO (IxContT m i i) where+	liftIO = ilift . liftIO ++newtype IxCont r o a = IxCont (IxContT Identity r o a) +	deriving (IxFunctor, IxPointed, IxApplicative, IxMonad, IxMonadCont)+++runIxCont :: IxCont r o a -> (a -> o) -> r +runIxCont (IxCont k) f = runIdentity $ runIxContT k (return . f)++runIxCont_ :: IxCont r a a -> r+runIxCont_ m = runIxCont m id++-- instance MonadCont (IxCont i i) where +--	callCC f = shift (\k -> f k >>>= k)++instance Functor (IxCont i j) where+	fmap = imap++instance Pointed (IxCont i i) where+	point = ireturn++instance Applicative (IxCont i i) where+	pure = ireturn+	(<*>) = iap++instance Monad (IxCont i i) where+	return = ireturn+	m >>= k = ibind k m+
+ Control/Monad/Indexed/State.hs view
@@ -0,0 +1,160 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Monad.Indexed.State+-- Copyright   :  (C) 2008 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+--+-- Maintainer  :  Reiner Pope <reiner.pope@gmail.com>+-- Stability   :  experimental +-- Portability :  portable (although the MTL instances aren't!)+--+----------------------------------------------------------------------------+module Control.Monad.Indexed.State +	( IxMonadState(..)+	, imodify+	, igets+	, IxStateT(..)+	, IxState(..)+	) where++import Control.Applicative+import Data.Bifunctor+import Control.Monad.Indexed+import Control.Monad.Indexed.Trans+import Control.Monad.Indexed.Fix+import Control.Monad.State+import Control.Monad.Writer+import Control.Monad.Reader+import Control.Monad.Cont+import Control.Monad.Error.Class++class IxMonad m => IxMonadState m where+	iget :: m i i i+	iput :: j -> m i j ()++imodify :: IxMonadState m => (i -> j) -> m i j ()+imodify f = iget >>>= iput . f++igets :: IxMonadState m => (i -> a) -> m i i a+igets f = iget >>>= ireturn . f++-- Indexed State Monad+	+newtype IxState i j a = IxState { runIxState :: i -> (a, j) }++instance Functor (IxState i j) where+	fmap = imap++instance IxFunctor IxState where+	imap f m = IxState (first f . runIxState m)++instance IxPointed IxState where+	ireturn = IxState . (,)++instance IxApplicative IxState where+	iap = iapIxMonad++instance IxMonad IxState where+	ibind f m = IxState $ \s1 -> let (a,s2) = runIxState m s1 in runIxState (f a) s2 ++instance IxMonadState IxState where+	iget = IxState (\x -> (x,x))+	iput x = IxState (\_ -> ((),x))++instance Bifunctor (IxState i) where +	bimap f g m = IxState $ bimap g f . runIxState m++instance Monad (IxState i i) where+	return = ireturn+	m >>= k = ibind k m ++instance Applicative (IxState i i) where+	pure = ireturn+	(<*>) = iap++instance MonadState i (IxState i i) where+	get = iget+	put = iput++instance MonadFix (IxState i i) where+    mfix = imfix++instance IxMonadFix IxState where+    imfix f = IxState $ \s -> let (a, s') = runIxState (f a) s in (a, s')+++-- Indexed State Monad Transformer++newtype IxStateT m i j a = IxStateT { runIxStateT :: i -> m (a, j) }++instance Monad m => Functor (IxStateT m i j) where+	fmap = imap++instance Monad m => IxFunctor (IxStateT m) where+	imap f m = IxStateT $ \s -> runIxStateT m s >>= \(x,s') -> return (f x, s')++instance Monad m => IxPointed (IxStateT m) where+    	ireturn a = IxStateT $ \s -> return (a, s)++instance Monad m => IxApplicative (IxStateT m) where+   	iap = iapIxMonad ++instance Monad m => IxMonad (IxStateT m) where+    	ibind k m = IxStateT $ \s -> runIxStateT m s >>= \ ~(a, s') -> runIxStateT (k a) s'++instance Monad m => Bifunctor (IxStateT m i) where+	bimap f g m = IxStateT $ liftM (bimap g f) . runIxStateT m++instance Monad m => IxMonadState (IxStateT m) where+	iget   = IxStateT $ \s -> return (s, s)+	iput s = IxStateT $ \_ -> return ((), s)++instance MonadPlus m => IxMonadZero (IxStateT m) where+	imzero = IxStateT $ const mzero++instance MonadPlus m => IxMonadPlus (IxStateT m) where+	m `implus` n = IxStateT $ \s -> runIxStateT m s `mplus` runIxStateT n s++instance MonadFix m => IxMonadFix (IxStateT m) where+	imfix f = IxStateT $ \s -> mfix $ \ ~(a, _) -> runIxStateT (f a) s++instance MonadFix m => MonadFix (IxStateT m i i) where+	mfix = imfix++instance Monad m => Monad (IxStateT m i i) where+	return = ireturn+	m >>= k = ibind k m ++instance Monad m => Applicative (IxStateT m i i) where+	pure = ireturn+	(<*>) = iap++instance Monad m => MonadState i (IxStateT m i i) where+	get = iget+	put = iput++instance IxMonadTrans IxStateT where+	ilift m = IxStateT $ \s -> m >>= \a -> return (a, s)++instance MonadIO m => MonadIO (IxStateT m i i) where+	liftIO = ilift . liftIO++instance MonadReader r m => MonadReader r (IxStateT m i i) where+	ask = ilift ask+	local f m = IxStateT (local f . runIxStateT m)++instance MonadCont m => MonadCont (IxStateT m i i) where+	callCC f = IxStateT $ \s -> callCC $ \k -> runIxStateT (f (\a -> IxStateT $ \s' -> k (a,s'))) s++instance MonadError e m => MonadError e (IxStateT m i i) where+	throwError = ilift . throwError+	m `catchError` h = IxStateT $ \s -> runIxStateT m s `catchError` \e -> runIxStateT (h e) s++instance MonadWriter w m => MonadWriter w (IxStateT m i i) where+	tell = ilift . tell+	listen m = IxStateT $ \s -> do +		~((a,s'),w) <- listen (runIxStateT m s)+		return ((a,w),s')+	pass m = IxStateT $ \s -> pass $ do+		~((a,f),s') <- runIxStateT m s+		return ((a,s'),f)
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2012, Edward A. 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:++    * 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 name of Edward A. Kmett nor the names of other+      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
+ indexed-extras.cabal view
@@ -0,0 +1,41 @@+Name:                indexed-extras+Version:             0.1+Synopsis:            Indexed functors, monads and comonads that require extensions to Haskell98+Description:         Indexed functors, monads and comonads that require extensiosn to Haskell98+License:             BSD3+License-file:        LICENSE+Author:              Edward A. Kmett+Maintainer:          Reiner Pope <reiner.pope@gmail.com>+Copyright:           +    Copyright (C) 2012 Reiner Pope,+    Copyright (C) 2008 Edward A. Kmett, +    Copyright (C) 2004--2008 Dave Menendez, +    Copyright (C) 2007 Iavor Diatchki+Category:            Control+Build-type:          Simple+Cabal-version:       >=1.6+homepage:            https://github.com/reinerp/indexed-extras+bug-reports:         https://github.com/reinerp/indexed-extras/issues++source-repository head+  type:                 git+  location:             git://github.com/reinerp/indexed-extras.git++Library+  Exposed-modules:+     Control.Monad.Indexed.Cont,+     Control.Monad.Indexed.State+  Build-depends:+     base < 5,+     indexed < 0.2,+     mtl < 2.1,+     pointed < 2.1,+     bifunctors < 0.2+  ghc-options:+     -Wall+  Extensions:+     UndecidableInstances,+     GeneralizedNewtypeDeriving,+     FlexibleInstances,+     MultiParamTypeClasses,+     Rank2Types