tree-monad 0.2.1 → 0.3
raw patch · 3 files changed
+65/−30 lines, 3 filesdep ~base
Dependency ranges changed: base
Files
- Control/Monad/SearchTree.hs +32/−14
- LICENSE +30/−13
- tree-monad.cabal +3/−3
Control/Monad/SearchTree.hs view
@@ -2,7 +2,7 @@ -- | -- Module : Control.Monad.SearchTree -- Copyright : Sebastian Fischer--- License : PublicDomain+-- License : BSD3 -- -- Maintainer : Sebastian Fischer (sebf@informatik.uni-kiel.de) -- Stability : experimental@@ -20,6 +20,7 @@ module Control.Monad.SearchTree ( SearchTree(..), Search, searchTree ) where import Control.Monad+import Control.Applicative -- | -- The type @SearchTree a@ represents non-deterministic computations@@ -27,8 +28,20 @@ data SearchTree a = None | One a | Choice (SearchTree a) (SearchTree a) deriving Show -instance Monad SearchTree- where+instance Functor SearchTree where+ fmap _ None = None+ fmap f (One x) = One (f x)+ fmap f (Choice s t) = Choice (fmap f s) (fmap f t)++instance Applicative SearchTree where+ pure = return+ (<*>) = ap++instance Alternative SearchTree where+ empty = mzero+ (<|>) = mplus++instance Monad SearchTree where return = One None >>= _ = None@@ -37,12 +50,10 @@ fail _ = None -instance MonadPlus SearchTree- where+instance MonadPlus SearchTree where mzero = None mplus = Choice - -- | -- Another search monad based on continuations that produce search -- trees.@@ -57,15 +68,22 @@ searchTree :: Search a -> SearchTree a searchTree a = search a One -instance Monad Search- where+instance Functor Search where+ fmap f a = Search (\k -> search a (k . f))++instance Applicative Search where+ pure = return+ (<*>) = ap++instance Alternative Search where+ empty = mzero+ (<|>) = mplus++instance Monad Search where return x = Search ($x) a >>= f = Search (\k -> search a (\x -> search (f x) k)) fail _ = mzero -instance MonadPlus Search- where- mzero = Search (const None)- a `mplus` b = Search (\k -> search a k `Choice` search b k)--+instance MonadPlus Search where+ mzero = Search (const mzero)+ a `mplus` b = Search (\k -> search a k `mplus` search b k)
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.
tree-monad.cabal view
@@ -1,5 +1,5 @@ Name: tree-monad-Version: 0.2.1+Version: 0.3 Cabal-Version: >= 1.6 Synopsis: Non-Determinism Monad for Tree Search Description: @@ -9,7 +9,7 @@ constructors represent mzero, return, and mplus. Category: Control, Monads-License: PublicDomain+License: BSD3 License-File: LICENSE Author: Sebastian Fischer Maintainer: 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.SearchTree Ghc-Options: -Wall Extensions: Rank2Types