objective 0.5 → 0.5.1
raw patch · 5 files changed
+76/−18 lines, 5 filesdep −freedep −profunctors
Dependencies removed: free, profunctors
Files
- objective.cabal +2/−2
- src/Control/Monad/Objective/Class.hs +13/−1
- src/Control/Object.hs +37/−15
- src/Data/Functor/PushPull.hs +12/−0
- src/Data/Functor/Request.hs +12/−0
objective.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: objective -version: 0.5 +version: 0.5.1 synopsis: Extensible objects description: Stateful effect transducer homepage: https://github.com/fumieval/objective @@ -26,7 +26,7 @@ , Data.Functor.PushPull -- other-modules: other-extensions: MultiParamTypeClasses, KindSignatures, TypeFamilies - build-depends: base >=4.5 && <5, transformers >= 0.3 && <0.5, free >= 4.0 && <5, clean-unions < 0.2, profunctors > 4.0 && <5, elevator + build-depends: base >=4.5 && <5, transformers >= 0.3 && <0.5, clean-unions < 0.2, elevator ghc-options: -Wall hs-source-dirs: src default-language: Haskell2010
src/Control/Monad/Objective/Class.hs view
@@ -5,7 +5,19 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE CPP #-} - +----------------------------------------------------------------------------- +-- | +-- Module : Control.Monad.Objective.IO +-- Copyright : (c) Fumiaki Kinoshita 2014 +-- License : BSD3 +-- +-- Maintainer : Fumiaki Kinoshita <fumiexcel@gmail.com> +-- Stability : experimental +-- Portability : non-portable +-- +-- 'MonadObjective' class and operations +-- +----------------------------------------------------------------------------- module Control.Monad.Objective.Class where import Control.Object
src/Control/Object.hs view
@@ -1,7 +1,20 @@-{-# LANGUAGE Rank2Types, MultiParamTypeClasses, FlexibleInstances, FlexibleContexts #-} -{-# LANGUAGE DeriveFunctor, DeriveDataTypeable #-} -{-# LANGUAGE FunctionalDependencies, UndecidableInstances #-} -{-# LANGUAGE TypeOperators, TupleSections, GADTs #-} +{-# LANGUAGE Rank2Types, FlexibleInstances, FlexibleContexts, TypeOperators, CPP #-} +#if __GLASGOW_HASKELL__ >= 707 +{-# LANGUAGE DeriveDataTypeable #-} +#endif +----------------------------------------------------------------------------- +-- | +-- Module : Control.Object +-- Copyright : (c) Fumiaki Kinoshita 2014 +-- License : BSD3 +-- +-- Maintainer : Fumiaki Kinoshita <fumiexcel@gmail.com> +-- Stability : experimental +-- Portability : non-portable +-- +-- Stateful effect transducer: The Mealy machine for effects. +-- +----------------------------------------------------------------------------- module Control.Object ( -- * Construction Object(..), @@ -14,7 +27,6 @@ (.>>.), transObject, adaptObject, - sequential, -- * Extensible objects loner, (.|>.), @@ -26,14 +38,31 @@ import Control.Monad import Data.Typeable import Control.Applicative -import Control.Monad.Free import Data.OpenUnion1.Clean -- | The type 'Object e m' represents objects which can handle messages @e@, perform actions in the environment @m@. -- It can be thought of as an automaton that converts effects. -- 'Object's can be composed just like functions using '.>>.'; the identity element is 'echo'. -newtype Object e m = Object { runObject :: forall x. e x -> m (x, Object e m) } deriving Typeable +newtype Object e m = Object { runObject :: forall x. e x -> m (x, Object e m) } +#if __GLASGOW_HASKELL__ >= 707 + deriving (Typeable) +#else +instance (Typeable1 f, Typeable1 m) => Typeable (Object f m) where + typeOf t = mkTyConApp objectTyCon [typeOf1 (f t), typeOf1 (g t)] where + f :: Object f m -> f a + f = undefined + g :: Object f m -> m a + g = undefined +objectTyCon :: TyCon +#if __GLASGOW_HASKELL__ < 704 +objectTyCon = mkTyCon "Control.Object.Object" +#else +objectTyCon = mkTyCon3 "object" "Control.Object" "Object" +#endif +{-# NOINLINE objectTyCon #-} +#endif + -- | Lift a natural transformation into an object. liftO :: Functor f => (forall x. e x -> f x) -> Object e f liftO f = Object $ fmap (\x -> (x, liftO f)) . f @@ -68,14 +97,6 @@ go s = Object $ liftM (\(a, s') -> (a, go s')) . flip runStateT s . h {-# INLINE stateful #-} --- | Convert a /method sequence/ into a sequential /method execution/. -sequential :: Monad m => Object e m -> Object (Free e) m -sequential obj = Object $ \x -> case x of - Pure a -> return (a, sequential obj) - Free f -> do - (a, obj') <- runObject obj f - runObject (sequential obj') a - -- | A mutable variable. variable :: Applicative f => s -> Object (State s) f variable s = Object $ \m -> let (a, s') = runState m s in pure (a, variable s') @@ -98,3 +119,4 @@ p .|>. q = Object $ fmap (fmap (.|>.q)) . runObject p ||> fmap (fmap (p .|>.)) . runObject q infixr 3 .|>. +
src/Data/Functor/PushPull.hs view
@@ -1,8 +1,20 @@ {-# LANGUAGE DeriveFunctor, DeriveDataTypeable, ConstraintKinds, FlexibleContexts #-} +----------------------------------------------------------------------------- +-- | +-- Module : Data.Functor.PushPull +-- Copyright : (c) Fumiaki Kinoshita 2014 +-- License : BSD3 +-- +-- Maintainer : Fumiaki Kinoshita <fumiexcel@gmail.com> +-- Stability : experimental +-- Portability : non-portable +-- +----------------------------------------------------------------------------- module Data.Functor.PushPull where import Data.Typeable import Control.Elevator +-- | The type for asynchronous input/output. data PushPull a b r = Push a r | Pull (b -> r) deriving (Functor, Typeable) instance Tower (PushPull a b)
src/Data/Functor/Request.hs view
@@ -1,9 +1,21 @@ {-# LANGUAGE DeriveFunctor, DeriveDataTypeable, ConstraintKinds, FlexibleContexts #-} +----------------------------------------------------------------------------- +-- | +-- Module : Data.Functor.Request +-- Copyright : (c) Fumiaki Kinoshita 2014 +-- License : BSD3 +-- +-- Maintainer : Fumiaki Kinoshita <fumiexcel@gmail.com> +-- Stability : experimental +-- Portability : non-portable +-- +----------------------------------------------------------------------------- module Data.Functor.Request where import Data.Typeable import Control.Elevator import Control.Monad +-- | 'Request a b' is the type of a request that sends @a@ to receive @b@. data Request a b r = Request a (b -> r) deriving (Functor, Typeable) instance Tower (Request a b)