artery 0.1 → 0.1.1
raw patch · 2 files changed
+15/−10 lines, 2 filesdep ~transformers
Dependency ranges changed: transformers
Files
- Control/Artery.hs +13/−8
- artery.cabal +2/−2
Control/Artery.hs view
@@ -10,6 +10,7 @@ , feedback , delay1 , delay + , cartridge , module Control.Arrow) where import qualified Control.Category @@ -19,6 +20,8 @@ import Data.Monoid import Data.Profunctor import Control.Monad.Trans.State +import Control.Concurrent +import Control.Monad.IO.Class -- | 'Artery' is a device that produces a value from the input every beat. newtype Artery m i o = Artery { unArtery :: forall r. i -> (o -> Artery m i o -> m r) -> m r } @@ -88,6 +91,12 @@ fromInteger = pure . fromInteger {-# INLINE fromInteger #-} +instance Fractional o => Fractional (Artery m i o) where + (/) = liftA2 (/) + {-# INLINE (/) #-} + recip = fmap recip + fromRational = pure . fromRational + instance Monoid o => Monoid (Artery m i o) where mempty = pure mempty {-# INLINE mempty #-} @@ -148,11 +157,7 @@ runList ar (x:xs) = unArtery ar x $ \y cont -> (y:) <$> runList cont xs runList _ [] = pure [] -triggered :: Monoid a => [a] -> Artery m Bool a -triggered w = go [] where - zipLong (x:xs) (y:ys) = mappend x y : zipLong xs ys - zipLong xs [] = xs - zipLong [] ys = ys - go wav = Artery $ \i cont -> case (if i then id else zipLong w) wav of - x:xs -> cont x (go xs) - _ -> cont mempty (go [])+cartridge :: MonadIO m => MVar (Artery m i o) -> Artery m i o +cartridge ref = go where + go = Artery $ \i cont -> liftIO (takeMVar ref) + >>= \a -> unArtery a i $ \o a' -> liftIO (putMVar ref a') >> cont o go
artery.cabal view
@@ -1,5 +1,5 @@ name: artery -version: 0.1 +version: 0.1.1 synopsis: A simple, arrow-based reactive programming description: This package only provides Artery type and associated operations. homepage: https://github.com/fumieval/artery @@ -16,6 +16,6 @@ exposed-modules: Control.Artery -- other-modules: other-extensions: Rank2Types - build-depends: base == 4.*, containers, profunctors >= 3.0 && < 5, transformers == 0.3.* + build-depends: base == 4.*, containers, profunctors >= 3.0 && < 5, transformers >= 0.3 && <5 -- hs-source-dirs: default-language: Haskell2010