packages feed

tree-monad 0.1 → 0.2

raw patch · 2 files changed

+32/−3 lines, 2 files

Files

Control/Monad/SearchTree.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE Rank2Types #-} -- | -- Module      : Control.Monad.SearchTree -- Copyright   : Sebastian Fischer@@ -16,7 +17,7 @@ -- search strategies that evaluate different parts of the search space -- concurrently. -module Control.Monad.SearchTree ( SearchTree(..) ) where+module Control.Monad.SearchTree ( SearchTree(..), Search, searchTree ) where  import Control.Monad @@ -24,6 +25,7 @@ -- 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 Monad SearchTree  where@@ -39,4 +41,30 @@  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 Monad Search+ where+  return x = Search ($x)+  a >>= f  = Search (\k -> search a (\x -> search (f x) k))++instance MonadPlus Search+ where+  mzero       = Search (const None)+  a `mplus` b = Search (\k -> search a k `Choice` search b k)+ 
tree-monad.cabal view
@@ -1,5 +1,5 @@ Name:          tree-monad-Version:       0.1+Version:       0.2 Cabal-Version: >= 1.6 Synopsis:      Non-Determinism Monad for Tree Search Description:   @@ -14,7 +14,7 @@ Author:        Sebastian Fischer Maintainer:    sebf@informatik.uni-kiel.de Bug-Reports:   mailto:sebf@informatik.uni-kiel.de-Homepage:      http://github.com/sebfisch/tree-monad+Homepage:      http://sebfisch.github.com/tree-monad Build-Type:    Simple Stability:     experimental @@ -24,6 +24,7 @@   Build-Depends:    base   Exposed-Modules:  Control.Monad.SearchTree   Ghc-Options:      -Wall+  Extensions:       Rank2Types  Source-Repository head   type:     git