packages feed

minioperational (empty) → 0.1

raw patch · 5 files changed

+154/−0 lines, 5 filesdep +basedep +freedep +kan-extensionssetup-changed

Dependencies added: base, free, kan-extensions, transformers

Files

+ Control/Monad/Operational/Class.hs view
@@ -0,0 +1,69 @@+{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances #-}
+{-# LANGUAGE UndecidableInstances #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Control.Monad.Operational.Class
+-- Copyright   :  (C) 2012-2013 Fumiaki Kinoshita
+-- License     :  BSD-style (see the file LICENSE)
+--
+-- Maintainer  :  Fumiaki Kinsohita <fumiexcel@gmail.com>
+-- Stability   :  experimental
+-- Portability :  non-portable
+--
+-- A class for operational monads
+----------------------------------------------------------------------------
+module Control.Monad.Operational.Class (Operational(..)) where
+
+import Control.Monad.Trans.Reader
+import qualified Control.Monad.Trans.State.Strict as Strict
+import qualified Control.Monad.Trans.State.Lazy as Lazy
+import qualified Control.Monad.Trans.Writer.Strict as Strict
+import qualified Control.Monad.Trans.Writer.Lazy as Lazy
+import qualified Control.Monad.Trans.RWS.Strict as Strict
+import qualified Control.Monad.Trans.RWS.Lazy as Lazy
+import Control.Monad.Trans.Cont
+import Control.Monad.Trans.Maybe
+import Control.Monad.Trans.List
+import Control.Monad.Trans.Error
+import Control.Monad.Trans.Identity
+import Control.Monad.Trans.Class
+import Data.Monoid
+
+class Monad m => Operational t m | m -> t where
+  singleton :: t a -> m a
+
+instance (Operational f m) => Operational f (ReaderT e m) where
+  singleton = lift . singleton
+
+instance (Operational f m) => Operational f (Lazy.StateT s m) where
+  singleton = lift . singleton
+
+instance (Operational f m) => Operational f (Strict.StateT s m) where
+  singleton = lift . singleton
+
+instance (Operational f m) => Operational f (ContT r m) where
+  singleton = lift . singleton
+
+instance (Operational f m, Monoid w) => Operational f (Lazy.WriterT w m) where
+  singleton = lift . singleton
+
+instance (Operational f m, Monoid w) => Operational f (Strict.WriterT w m) where
+  singleton = lift . singleton
+
+instance (Operational f m, Monoid w) => Operational f (Strict.RWST r w s m) where
+  singleton = lift . singleton
+
+instance (Operational f m, Monoid w) => Operational f (Lazy.RWST r w s m) where
+  singleton = lift . singleton
+
+instance (Operational f m) => Operational f (MaybeT m) where
+  singleton = lift . singleton
+
+instance (Operational f m) => Operational f (IdentityT m) where
+  singleton = lift . singleton
+
+instance (Operational f m) => Operational f (ListT m) where
+  singleton = lift . singleton
+
+instance (Operational f m, Error e) => Operational f (ErrorT e m) where
+  singleton = lift . singleton
+ Control/Monad/Operational/Mini.hs view
@@ -0,0 +1,26 @@+{-# LANGUAGE Rank2Types, GADTs, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Control.Monad.Operational.Mini
+-- Copyright   :  (C) 2012-2013 Fumiaki Kinoshita
+-- License     :  BSD-style (see the file LICENSE)
+--
+-- Maintainer  :  Fumiaki Kinsohita <fumiexcel@gmail.com>
+-- Stability   :  experimental
+-- Portability :  non-portable
+--
+-- Simple operational monad from a free monad
+----------------------------------------------------------------------------
+module Control.Monad.Operational.Mini (Program, interpret, module Control.Monad.Operational.Class) where
+
+import Data.Functor.Yoneda.Contravariant
+import Control.Monad.Free.Church
+import Control.Monad.Operational.Class
+
+type Program t = F (Yoneda t)
+
+interpret :: Monad m => (forall x. t x -> m x) -> Program t a -> m a
+interpret e (F m) = m return (\(Yoneda f t) -> e t >>= f)
+
+instance Operational t (Program t) where
+    singleton = liftF . liftYoneda
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Fumiaki Kinoshita
+
+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 Fumiaki Kinoshita 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
+ minioperational.cabal view
@@ -0,0 +1,27 @@+-- Initial minioperational.cabal generated by cabal init.  For further 
+-- documentation, see http://haskell.org/cabal/users-guide/
+
+name:                minioperational
+version:             0.1
+synopsis:            fast and simple operational monad
+description:         This package provides tiny implementation of operational monad.
+homepage:            https://github.com/fumieval/minioperational
+license:             BSD3
+license-file:        LICENSE
+author:              Fumiaki Kinoshita
+maintainer:          Fumiaki Kinoshita <fumiexcel@gmail.com>
+copyright:           Copyright (C) 2013 Fumiaki Kinoshita
+category:            Control
+build-type:          Simple
+cabal-version:       >=1.10
+
+source-repository head
+  type: git
+  location: https://github.com/fumieval/minioperational.git
+
+library
+  default-language:   Haskell2010
+  ghc-options: -Wall -O2
+  exposed-modules:     Control.Monad.Operational.Mini, Control.Monad.Operational.Class
+  -- other-modules:       
+  build-depends:       base ==4.*, kan-extensions ==3.*, free ==3.*, transformers >= 0.2.0 && <0.4