Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added instances for Applicative and Alternative

  • Loading branch information...
commit cabff94c2691227a8f9fbbcf9d7557fdd7306596 1 parent 1055a5b
@sebfisch authored
Showing with 47 additions and 39 deletions.
  1. +13 −22 Control/Monad/Stream.hs
  2. +31 −14 LICENSE
  3. +3 −3 stream-monad.cabal
View
35 Control/Monad/Stream.hs
@@ -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 @@ instance MonadPlus Stream
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
View
45 LICENSE
@@ -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.
-
-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.
+Copyright (c) 2010, Thomas Wilke, Frank Huch, Sebastian Fischer
+
+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.
View
6 stream-monad.cabal
@@ -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 @@ Description: This Haskell library provides an implementation of the
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 @@ Stability: experimental
Extra-Source-Files: README
Library
- Build-Depends: base
+ Build-Depends: base >= 3 && < 5
Exposed-Modules: Control.Monad.Stream
Ghc-Options: -Wall
Please sign in to comment.
Something went wrong with that request. Please try again.