tree-monad-0.3/0000755000000000000000000000000011454020175011574 5ustar0000000000000000tree-monad-0.3/LICENSE0000644000000000000000000000276711454020175012615 0ustar0000000000000000Copyright (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. tree-monad-0.3/README0000644000000000000000000000072511454020175012460 0ustar0000000000000000Non-Determinism Monad for Tree Search ===================================== This Haskell library provides an implementation of the MonadPlus type class that represents the search space as a tree whose constructors represent mzero, return, and mplus. Such a tree can be used to implement different search strategies, e.g., by using a queue. It can also be used as a basis for parallel search strategies that evaluate different parts of the search space concurrently. tree-monad-0.3/Setup.hs0000644000000000000000000000006011454020175013224 0ustar0000000000000000import Distribution.Simple main = defaultMain tree-monad-0.3/tree-monad.cabal0000644000000000000000000000157211454020175014620 0ustar0000000000000000Name: tree-monad Version: 0.3 Cabal-Version: >= 1.6 Synopsis: Non-Determinism Monad for Tree Search Description: This Haskell library provides an implementation of the MonadPlus type class that represents the search space as a tree whose constructors represent mzero, return, and mplus. Category: Control, Monads License: BSD3 License-File: LICENSE Author: Sebastian Fischer Maintainer: sebf@informatik.uni-kiel.de Bug-Reports: mailto:sebf@informatik.uni-kiel.de Homepage: http://sebfisch.github.com/tree-monad Build-Type: Simple Stability: experimental Extra-Source-Files: README Library Build-Depends: base >= 3 && < 5 Exposed-Modules: Control.Monad.SearchTree Ghc-Options: -Wall Extensions: Rank2Types Source-Repository head type: git location: git://github.com/sebfisch/tree-monad.git tree-monad-0.3/Control/0000755000000000000000000000000011454020175013214 5ustar0000000000000000tree-monad-0.3/Control/Monad/0000755000000000000000000000000011454020175014252 5ustar0000000000000000tree-monad-0.3/Control/Monad/SearchTree.hs0000644000000000000000000000446311454020175016642 0ustar0000000000000000{-# LANGUAGE Rank2Types #-} -- | -- Module : Control.Monad.SearchTree -- Copyright : Sebastian Fischer -- License : BSD3 -- -- Maintainer : Sebastian Fischer (sebf@informatik.uni-kiel.de) -- Stability : experimental -- Portability : portable -- -- This Haskell library provides an implementation of the MonadPlus -- type class that represents the search space as a tree whose -- constructors represent mzero, return, and mplus. -- -- Such a tree can be used to implement different search strategies, -- e.g., by using a queue. It can also be used as a basis for parallel -- search strategies that evaluate different parts of the search space -- concurrently. module Control.Monad.SearchTree ( SearchTree(..), Search, searchTree ) where import Control.Monad import Control.Applicative -- | -- The type @SearchTree a@ represents non-deterministic computations -- as a tree structure. data SearchTree a = None | One a | Choice (SearchTree a) (SearchTree a) deriving Show 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 One x >>= f = f x Choice s t >>= f = Choice (s >>= f) (t >>= f) fail _ = None instance MonadPlus SearchTree where mzero = None mplus = Choice -- | -- Another search monad based on continuations that produce search -- trees. newtype Search a = Search { -- | Passes a continuation to a monadic search action. search :: forall r . (a -> SearchTree r) -> SearchTree r } -- | Computes the @SearchTree@ representation of a @Search@ action. searchTree :: Search a -> SearchTree a searchTree a = search a One 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 mzero) a `mplus` b = Search (\k -> search a k `mplus` search b k)