operational-class (empty) → 0.1.0.0
raw patch · 4 files changed
+119/−0 lines, 4 filesdep +basedep +operationaldep +transformerssetup-changed
Dependencies added: base, operational, transformers
Files
- LICENSE +22/−0
- Setup.hs +2/−0
- operational-class.cabal +27/−0
- src/Control/Monad/Operational/Class.hs +68/−0
+ LICENSE view
@@ -0,0 +1,22 @@+The MIT License (MIT)++Copyright (c) 2015 Sam Rijs++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ operational-class.cabal view
@@ -0,0 +1,27 @@+-- Initial operational-class.cabal generated by cabal init. For further+-- documentation, see http://haskell.org/cabal/users-guide/++name: operational-class+version: 0.1.0.0+synopsis: MonadProgram typeclass for the operational package+-- description:+homepage: https://github.com/srijs/haskell-operational-class+license: MIT+license-file: LICENSE+author: Sam Rijs+maintainer: srijs@airpost.net+-- copyright:+category: Control+build-type: Simple+-- extra-source-files:+cabal-version: >=1.10++library+ exposed-modules: Control.Monad.Operational.Class+ -- other-modules:+ -- other-extensions:+ build-depends: base >=4.6 && <5,+ transformers >=0.3,+ operational >=0.2+ hs-source-dirs: src+ default-language: Haskell2010
+ src/Control/Monad/Operational/Class.hs view
@@ -0,0 +1,68 @@+{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances, GADTs #-}++module Control.Monad.Operational.Class where++import Data.Monoid (Monoid)++import Control.Monad (liftM, join)+import Control.Monad.Operational+import Control.Monad.Trans.Class (MonadTrans, lift)++import Control.Monad.Trans.Reader (ReaderT)+import qualified Control.Monad.Trans.State.Strict as Strict (StateT)+import qualified Control.Monad.Trans.State.Lazy as Lazy (StateT)+import Control.Monad.Trans.Cont (ContT)+import qualified Control.Monad.Trans.Writer.Strict as Strict (WriterT)+import qualified Control.Monad.Trans.Writer.Lazy as Lazy (WriterT)+import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST)+import qualified Control.Monad.Trans.RWS.Lazy as Lazy (RWST)+import Control.Monad.Trans.Maybe (MaybeT)+import Control.Monad.Trans.Identity (IdentityT)+import Control.Monad.Trans.List (ListT)++class Monad m => MonadProgram instr m | m -> instr where+ wrap :: Program instr (m a) -> m a++wrapT :: (m ~ t n, Monad m, MonadTrans t, MonadProgram instr n) => Program instr (m a) -> m a+wrapT = join . lift . wrap . fmap return++liftP :: MonadProgram instr m => Program instr a -> m a+liftP p = wrap $ liftM return p++instance Monad m => MonadProgram instr (ProgramT instr m) where+ wrap = eval . view+ where eval (Return a) = a+ eval (i :>>= k) = singleton i >>= wrap . k++instance (MonadProgram instr m) => MonadProgram instr (ReaderT e m) where+ wrap = wrapT++instance (MonadProgram instr m) => MonadProgram instr (Strict.StateT s m) where+ wrap = wrapT++instance (MonadProgram instr m) => MonadProgram instr (Lazy.StateT s m) where+ wrap = wrapT++instance (MonadProgram instr m) => MonadProgram instr (ContT r m) where+ wrap = wrapT++instance (MonadProgram instr m, Monoid w) => MonadProgram instr (Strict.WriterT w m) where+ wrap = wrapT++instance (MonadProgram instr m, Monoid w) => MonadProgram instr (Lazy.WriterT w m) where+ wrap = wrapT++instance (MonadProgram instr m, Monoid w) => MonadProgram instr (Strict.RWST r w s m) where+ wrap = wrapT++instance (MonadProgram instr m, Monoid w) => MonadProgram instr (Lazy.RWST r w s m) where+ wrap = wrapT++instance (MonadProgram instr m) => MonadProgram instr (MaybeT m) where+ wrap = wrapT++instance (MonadProgram instr m) => MonadProgram instr (IdentityT m) where+ wrap = wrapT++instance (MonadProgram instr m) => MonadProgram instr (ListT m) where+ wrap = wrapT