stream-monad 0.2 → 0.3
raw patch · 3 files changed
+46/−38 lines, 3 filesdep ~base
Dependency ranges changed: base
Files
- Control/Monad/Stream.hs +13/−22
- LICENSE +30/−13
- stream-monad.cabal +3/−3
Control/Monad/Stream.hs view
@@ -1,7 +1,7 @@ -- | -- Module : Control.Monad.Stream--- Copyright : Oleg Kiselyov--- License : PublicDomain+-- Copyright : Oleg Kiselyov, Sebastian Fischer+-- License : BSD3 -- -- Maintainer : Sebastian Fischer (sebf@informatik.uni-kiel.de) -- Stability : experimental@@ -27,6 +27,7 @@ module Control.Monad.Stream ( Stream, suspended, runStream ) where import Control.Monad+import Control.Applicative -- | -- Results of non-deterministic computations of type @Stream a@ can be@@ -80,24 +81,14 @@ Susp xs `mplus` Cons y ys = Cons y (xs `mplus` ys) Susp xs `mplus` Susp ys = suspended (xs `mplus` ys) --- |--- The class @MonadTimes@ defines an operation to compute the--- cartesian product of the results of two monadic operations. A--- sequential default implementation is given in terms of @>>=@ but--- specific instances can ovverride this definition to evaluate both--- arguments in parallel or interleaved.--- -class Monad m => MonadTimes m- where- mtimes :: m a -> m b -> m (a,b)- mtimes = liftM2 (,)+instance Applicative Stream where+ pure = Single -instance MonadTimes Stream- where- Nil `mtimes` _ = Nil- Single x `mtimes` ys = fmap (\y -> (x,y)) ys -- or use liftM ?- Cons x xs `mtimes` ys = fmap (\y -> (x,y)) ys `mplus` (xs `mtimes` ys)- _ `mtimes` Nil = Nil- Susp xs `mtimes` Single y = fmap (\x -> (x,y)) xs- Susp xs `mtimes` Cons y ys = fmap (\x -> (x,y)) xs `mplus` (xs `mtimes` ys)- Susp xs `mtimes` Susp ys = suspended (xs `mtimes` ys)+ Nil <*> _ = Nil+ Single f <*> xs = fmap f xs+ Cons f fs <*> xs = fmap f xs <|> (xs <**> fs)+ Susp fs <*> xs = suspended (xs <**> fs)++instance Alternative Stream where+ empty = Nil+ (<|>) = mplus
LICENSE view
@@ -1,15 +1,32 @@-ALL PUBLIC DOMAIN MATERIAL IS OFFERED AS-IS. NO REPRESENTATIONS OR-WARRANTIES OF ANY KIND ARE MADE CONCERNING THE MATERIALS, EXPRESS,-IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION,-WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR-PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS,-ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT-DISCOVERABLE.+Copyright (c) 2010, Thomas Wilke, Frank Huch, Sebastian Fischer -IN NO EVENT WILL THE AUTHOR(S), PUBLISHER(S), OR PRESENTER(S) OF ANY-PUBLIC DOMAIN MATERIAL BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY-SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES-ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF THE-AUTHOR(S), PUBLISHER(S), OR PRESENTER(S) HAVE BEEN ADVISED OF THE-POSSIBILITY OF SUCH DAMAGES.+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are+met:++ 1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ 2. 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.++ 3. Neither the name of the author nor the names of his contributors+ may be used to endorse or promote products derived from this+ software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+``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 OR+CONTRIBUTORS 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.
stream-monad.cabal view
@@ -1,5 +1,5 @@ Name: stream-monad-Version: 0.2+Version: 0.3 Cabal-Version: >= 1.6 Synopsis: Simple, Fair and Terminating Backtracking Monad Description: This Haskell library provides an implementation of the@@ -9,7 +9,7 @@ memory performance than other strategies with the same termination properties. Category: Control, Monads-License: PublicDomain+License: BSD3 License-File: LICENSE Author: Oleg Kiselyov, Sebastian Fischer Maintainer: Sebastian Fischer (sebf@informatik.uni-kiel.de)@@ -21,7 +21,7 @@ Extra-Source-Files: README Library- Build-Depends: base+ Build-Depends: base >= 3 && < 5 Exposed-Modules: Control.Monad.Stream Ghc-Options: -Wall