packages feed

quiver (empty) → 0.0.0.1

raw patch · 5 files changed

+193/−0 lines, 5 filesdep +basesetup-changed

Dependencies added: base

Files

+ LICENSE view
@@ -0,0 +1,28 @@++  Quiver+  ======++    Copyright © 2015 Patryk Zadarnowski «pat@jantar.org».+    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. ➂ The name of any+  author may not be used to endorse or promote products derived from this+  software without their specific prior written permission.++  THIS SOFTWARE IS PROVIDED “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 AUTHORS 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,3 @@+#! /usr/bin/env runhaskell+import Distribution.Simple+main = defaultMain
+ quiver.cabal view
@@ -0,0 +1,43 @@+name:           quiver+version:        0.0.0.1+synopsis:       Quiver finite stream processing library+homepage:       https://github.com/zadarnowski/quiver+category:       Control+stability:      alpha++author:         Patryk Zadarnowski+maintainer:     Patryk Zadarnowski <pat@jantar.org>++copyright:      Copyright (c) 2015 Patryk Zadarnowski++description:++    /Quiver/ is a powerful stream processing library for+    combinatorial and monadic transformations of both inductive+    and coinductive data structures.++cabal-version:  >= 1.18+build-type:     Simple+license:        BSD3+license-file:   LICENSE++source-repository head+  type:         git+  location:     https://github.com/zadarnowski/quiver.git++source-repository this+  type:         git+  location:     https://github.com/zadarnowski/quiver.git+  tag:          0.0.0.1++library+  hs-source-dirs:   src+  default-language: Haskell2010+  ghc-options:      -Wall -fno-warn-unused-do-bind -fno-warn-missing-signatures++  exposed-modules:+    Control.Quiver+    Control.Quiver.Internal++  build-depends:+    base >= 4.8 && < 5
+ src/Control/Quiver.lhs view
@@ -0,0 +1,63 @@+> {-# LANGUAGE RankNTypes, TupleSections #-}++> module Control.Quiver (+>   Q,+>   consume, produce, enclose, deliver,+>   decouple, evacuate,+>   fetch, fetch',+>   emit, emit', emit_,+>   liftQ,+>   (>>->), (>->>),+> ) where++> import Control.Quiver.Internal++> infixl 0 >>->, >->>++> fetch :: a' -> Q a' a b' b f (Maybe a)+> fetch x = Consume x (Deliver . Just) (Deliver Nothing)++> fetch' :: a' -> (forall x' x . Q x' x b' b f a) -> Q a' a b' b f a+> fetch' x r = Consume x Deliver r++> emit :: b -> Q a' a b' b f (Maybe b')+> emit y = Produce y (Deliver . Just) (Deliver Nothing)++> emit' :: b -> (forall x' x . Q a' a x' x f b') -> Q a' a b' b f b'+> emit' y r = Produce y Deliver r++> emit_ :: b -> Q a' a b' b f ()+> emit_ y = Produce y (Deliver . const ()) (Deliver ())++> liftQ :: Functor f => f c -> Q a' a b' b f c+> liftQ = Enclose . fmap Deliver++> (>>->) :: Functor f => Q a' a t' t f c1 -> Q t' t b' b f c2 -> Q a' a b' b f (c1, c2)+> (Consume x1 k1 r1) >>-> q2 = Consume x1 ((>>-> q2) . k1) (r1 >>-> q2)+> (Produce y1 k1 r1) >>-> q2 = loop q2+>  where+>   loop  (Consume x2 k2  _) = k1 x2 >>-> k2 y1+>   loop  (Produce y2 k2 r2) = Produce y2 (loop . k2) (loop' r2)+>   loop  (Enclose f2)       = Enclose (fmap loop f2)+>   loop  (Deliver z2)       = fmap (, z2) r1+>   loop' (Consume x2 k2  _) = k1 x2 >>-> k2 y1+>   loop' (Produce  _  _ r2) = loop' r2+>   loop' (Enclose f2)       = Enclose (fmap loop' f2)+>   loop' (Deliver z2)       = fmap (, z2) r1+> (Enclose f1) >>-> q2 = Enclose (fmap (>>-> q2) f1)+> (Deliver z1) >>-> q2 = fmap (z1 ,) (decouple q2)++> (>->>) :: Functor f => Q a' a t' t f c1 -> Q t' t b' b f c2 -> Q a' a b' b f (c1, c2)+> q1 >->> (Consume x2 k2 r2) = loop q1+>  where+>   loop  (Consume x1 k1 r1) = Consume x1 (loop . k1) (loop' r1)+>   loop  (Produce y1 k1  _) = k1 x2 >->> k2 y1+>   loop  (Enclose f1)       = Enclose (fmap loop f1)+>   loop  (Deliver z1)       = fmap (z1 ,) r2+>   loop' (Consume  _  _ t1) = loop' t1+>   loop' (Produce y1 k1  _) = k1 x2 >->> k2 y1+>   loop' (Enclose f1)       = Enclose (fmap loop' f1)+>   loop' (Deliver z1)       = fmap (z1 ,) r2+> q1 >->> (Produce y2 k2 r2) = Produce y2 ((q1 >->>) . k2) (q1 >->> r2)+> q1 >->> (Enclose f2)       = Enclose (fmap (q1 >->>) f2)+> q1 >->> (Deliver z2)       = fmap (, z2) (evacuate q1)
+ src/Control/Quiver/Internal.lhs view
@@ -0,0 +1,56 @@+> {-# LANGUAGE RankNTypes, TupleSections #-}++> module Control.Quiver.Internal (+>   Q (..),+>   consume, produce, enclose, deliver,+>   decouple, evacuate+> ) where++> data Q a' a b' b f c =+>     Consume a' (a  -> Q a' a b' b f c) (forall x' x . Q x' x b' b f c)+>   | Produce b  (b' -> Q a' a b' b f c) (forall x' x . Q a' a x' x f c)+>   | Enclose (f (Q a' a b' b f c))+>   | Deliver c++> consume :: a' -> (a  -> Q a' a b' b f c) -> (forall x' x . Q x' x b' b f c) -> Q a' a b' b f c+> consume = Consume++> produce :: b  -> (b' -> Q a' a b' b f c) -> (forall x' x . Q a' a x' x f c) -> Q a' a b' b f c+> produce = Produce++> enclose :: f (Q a' a b' b f c) -> Q a' a b' b f c+> enclose = Enclose++> deliver :: c -> Q a' a b' b f c+> deliver = Deliver++> instance Functor f => Functor (Q a' a b' b f) where+>   fmap ff (Consume x k r) = Consume x (fmap ff . k) (fmap ff r)+>   fmap ff (Produce y k r) = Produce y (fmap ff . k) (fmap ff r)+>   fmap ff (Enclose f)     = Enclose (fmap (fmap ff) f)+>   fmap ff (Deliver z)     = Deliver (ff z)++> instance Applicative f => Applicative (Q a' a b' b f) where+>   pure = Deliver+>   (Consume x k r) <*> q = Consume x ((<*> q) . k) (r <*> decouple q)+>   (Produce y k r) <*> q = Produce y ((<*> q) . k) (r <*> evacuate q)+>   (Enclose f)     <*> q = Enclose (fmap (<*> q) f)+>   (Deliver z)     <*> q = fmap z q++> instance Monad f => Monad (Q a' a b' b f) where+>   (Consume x k r) >>= kk = Consume x ((>>= kk) . k) (r >>= decouple . kk)+>   (Produce y k r) >>= kk = Produce y ((>>= kk) . k) (r >>= evacuate . kk)+>   (Enclose f)     >>= kk = Enclose (fmap (>>= kk) f)+>   (Deliver z)     >>= kk = kk z++> decouple :: Functor f => Q a' a b' b f c -> forall x' x . Q x' x b' b f c+> decouple (Consume _ _ r) = r+> decouple (Produce y k r) = Produce y (decouple . k) (decouple r)+> decouple (Enclose f) = Enclose (fmap decouple f)+> decouple (Deliver z) = Deliver z++> evacuate :: Functor f => Q a' a b' b f c -> forall x' x . Q a' a x' x f c+> evacuate (Consume x k r) = Consume x (evacuate . k) (evacuate r)+> evacuate (Produce _ _ r) = r+> evacuate (Enclose f) = Enclose (fmap evacuate f)+> evacuate (Deliver z) = Deliver z