HoleyMonoid 0.1 → 0.1.1
raw patch · 3 files changed
+36/−21 lines, 3 filessetup-changedPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.HoleyMonoid: data HoleyMonoid m r a
+ Data.HoleyMonoid: HoleyMonoid :: ((m -> r) -> a) -> HoleyMonoid m r a
+ Data.HoleyMonoid: bind :: HoleyMonoid m b c -> (m -> HoleyMonoid n a b) -> HoleyMonoid n a c
+ Data.HoleyMonoid: instance Applicative (HoleyMonoid m r)
+ Data.HoleyMonoid: instance Functor (HoleyMonoid m r)
+ Data.HoleyMonoid: instance Monad (HoleyMonoid m r)
+ Data.HoleyMonoid: newtype HoleyMonoid m r a
+ Data.HoleyMonoid: runHM :: HoleyMonoid m r a -> (m -> r) -> a
Files
- Data/HoleyMonoid.hs +24/−13
- HoleyMonoid.cabal +11/−8
- Setup.hs +1/−0
Data/HoleyMonoid.hs view
@@ -1,9 +1,8 @@ -- | Monoids with holes. The 'HoleyMonoid' allows building monoidal values of which certain components are to be filled in later. For example: ----- > > let holey = now "x = "--- > . later show--- > . now ", y = "--- > . later show+-- > > let holey :: (Show a, Show b) => HoleyMonoid String r (a -> b -> r)+-- > holey = now "x = " . later show . now ", y = " . later show+-- > -- > > run holey 3 5 -- > "x = 3, y = 5" --@@ -12,12 +11,13 @@ -- > import qualified Data.HoleyMonoid as HM module Data.HoleyMonoid (- HoleyMonoid, run,- now, later, map+ HoleyMonoid(..), run,+ now, later, bind, map ) where import Prelude hiding (id, (.), map)+import Control.Applicative import Control.Category import Data.Monoid @@ -34,26 +34,37 @@ id = now mempty f . g = f `bind` \a -> g `bind` \b -> now (a `mappend` b) +instance Functor (HoleyMonoid m r) where+ fmap f (HoleyMonoid g) = HoleyMonoid (f . g)++instance Applicative (HoleyMonoid m r) where+ pure x = HoleyMonoid (pure x)+ HoleyMonoid f <*> HoleyMonoid g = HoleyMonoid (f <*> g)++instance Monad (HoleyMonoid m r) where+ return x = HoleyMonoid (return x)+ HoleyMonoid f >>= g = HoleyMonoid (f >>= \x -> runHM (g x))+ -- | Insert a constant monoidal value. now :: m -> HoleyMonoid m r r now a = HoleyMonoid ($ a) --- | Monadic indexed bind for holey monoids.-bind :: HoleyMonoid m b c -> (m -> HoleyMonoid n a b) -> HoleyMonoid n a c-m `bind` f = HoleyMonoid $ \k -> runHM m (\a -> runHM (f a) k)- -- | Insert a monoidal value that is not specified until the computation is -- 'run'. The argument that is expected later is converted to the monoid type -- using the given conversion function. later :: (a -> m) -> HoleyMonoid m r (a -> r) later f = HoleyMonoid (. f) --- | Convert between underlying 'Monoid' types.+-- | Monadic indexed bind on the underlying 'Monoid' types.+bind :: HoleyMonoid m b c -> (m -> HoleyMonoid n a b) -> HoleyMonoid n a c+m `bind` f = HoleyMonoid $ \k -> runHM m (\a -> runHM (f a) k)++-- | Map between underlying 'Monoid' types. map :: (m -> n) -> HoleyMonoid m r a -> HoleyMonoid n r a map g m = HoleyMonoid (\k -> runHM m (k . g)) -- | Run the computation, resulting in a function that still expects some--- arguments. The number of arguments that is still expected will be equal to the--- number of 'later's the computation is built of.+-- arguments. The number of arguments that is still expected will be equal to+-- the number of 'later's the computation is built of. run :: HoleyMonoid m m a -> a run m = runHM m id
HoleyMonoid.cabal view
@@ -1,26 +1,29 @@ Name: HoleyMonoid-Version: 0.1+Version: 0.1.1 Synopsis: Monoids with holes. Description: The 'HoleyMonoid' allows building monoidal values of which certain components are to be filled in later. For example: .- > > let holey = now "x = "- > . later show- > . now ", y = "- > . later show+ > > let holey :: (Show a, Show b) => HoleyMonoid String r (a -> b -> r)+ > holey = now "x = " . later show . now ", y = " . later show+ > > > run holey 3 5 > "x = 3, y = 5" Author: Martijn van Steenbergen Maintainer: Martijn van Steenbergen <martijn@van.steenbergen.nl> Stability: Experimental-Copyright: Some Rights Reserved (CC) 2009 Martijn van Steenbergen-Homepage: http://code.google.com/p/monoid-cont/+Copyright: Some Rights Reserved (CC) 2009-2015 Martijn van Steenbergen+Homepage: https://github.com/MedeaMelana/HoleyMonoid -Cabal-Version: >= 1.2+Cabal-Version: >= 1.6 License: BSD3 License-file: LICENSE Category: Data Structures Build-type: Simple++Source-Repository head+ Type: git+ Location: https://github.com/MedeaMelana/HoleyMonoid Library Exposed-Modules: Data.HoleyMonoid
Setup.hs view
@@ -1,2 +1,3 @@ import Distribution.Simple+ main = defaultMain