tree-monad 0.3 → 0.3.1
raw patch · 4 files changed
+58/−49 lines, 4 filesdep ~basesetup-changednew-uploader
Dependency ranges changed: base
Files
- CHANGELOG.md +5/−0
- Control/Monad/SearchTree.hs +28/−20
- Setup.hs +0/−2
- tree-monad.cabal +25/−27
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for tree-monad++## 0.3.1 -- 2020-10-23++* Add instances for `MonadFail`
Control/Monad/SearchTree.hs view
@@ -1,28 +1,28 @@ {-# LANGUAGE Rank2Types #-}+ -- | -- Module : Control.Monad.SearchTree -- Copyright : Sebastian Fischer -- License : BSD3--- --- Maintainer : Sebastian Fischer (sebf@informatik.uni-kiel.de)+--+-- 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.Monad-import Control.Applicative+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)@@ -35,34 +35,36 @@ instance Applicative SearchTree where pure = return+ (<*>) = ap instance Alternative SearchTree where empty = mzero+ (<|>) = mplus instance Monad SearchTree where- return = One+ return = One - None >>= _ = None- One x >>= f = f x+ 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-- }+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@@ -73,17 +75,23 @@ 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+ 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)
Setup.hs view
@@ -1,4 +1,2 @@ import Distribution.Simple- main = defaultMain-
tree-monad.cabal view
@@ -1,31 +1,29 @@-Name: 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+cabal-version: >=1.10 -Extra-Source-Files: README+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- Build-Depends: base >= 3 && < 5- Exposed-Modules: Control.Monad.SearchTree- Ghc-Options: -Wall- Extensions: Rank2Types+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+source-repository head type: git- location: git://github.com/sebfisch/tree-monad.git+ location: git://github.com/nbun/tree-monad.git