tree-monad-0.3.1/0000755000000000000000000000000007346545000011737 5ustar0000000000000000tree-monad-0.3.1/CHANGELOG.md0000755000000000000000000000013307346545000013550 0ustar0000000000000000# Revision history for tree-monad ## 0.3.1 -- 2020-10-23 * Add instances for `MonadFail` tree-monad-0.3.1/Control/Monad/0000755000000000000000000000000007346545000014415 5ustar0000000000000000tree-monad-0.3.1/Control/Monad/SearchTree.hs0000644000000000000000000000462507346545000017005 0ustar0000000000000000{-# LANGUAGE Rank2Types #-} -- | -- Module : Control.Monad.SearchTree -- Copyright : Sebastian Fischer -- License : BSD3 -- -- Maintainer : Niels Bunkenburg (nbu@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.Applicative import Control.Monad -- | -- 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) instance MonadFail SearchTree where 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)) instance MonadFail Search where fail _ = mzero instance MonadPlus Search where mzero = Search (const mzero) a `mplus` b = Search (\k -> search a k `mplus` search b k) tree-monad-0.3.1/LICENSE0000644000000000000000000000276707346545000012760 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.1/README0000755000000000000000000000072507346545000012626 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.1/Setup.hs0000644000000000000000000000005607346545000013374 0ustar0000000000000000import Distribution.Simple main = defaultMain tree-monad-0.3.1/tree-monad.cabal0000644000000000000000000000205007346545000014753 0ustar0000000000000000cabal-version: >=1.10 name: tree-monad version: 0.3.1 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. homepage: http://sebfisch.github.com/tree-monad bug-reports: https://github.com/nbun/tree-monad/issues license: BSD3 license-file: LICENSE author: Sebastian Fischer maintainer: nbu@informatik.uni-kiel.de category: Control, Monads build-type: Simple extra-source-files: CHANGELOG.md, README library exposed-modules: Control.Monad.SearchTree other-extensions: Rank2Types build-depends: base >=4.13 && <4.15 default-language: Haskell2010 ghc-options: -Wall source-repository head type: git location: git://github.com/nbun/tree-monad.git