tree-monad 0.3.1 → 0.3.2
raw patch · 2 files changed
+21/−8 lines, 2 filesdep ~base
Dependency ranges changed: base
Files
- Control/Monad/SearchTree.hs +19/−6
- tree-monad.cabal +2/−2
Control/Monad/SearchTree.hs view
@@ -21,6 +21,7 @@ import Control.Applicative import Control.Monad+import Control.Monad.Fix -- | -- The type @SearchTree a@ represents non-deterministic computations@@ -34,7 +35,7 @@ fmap f (Choice s t) = Choice (fmap f s) (fmap f t) instance Applicative SearchTree where- pure = return+ pure = One (<*>) = ap @@ -44,8 +45,6 @@ (<|>) = mplus instance Monad SearchTree where- return = One- None >>= _ = None One x >>= f = f x Choice s t >>= f = Choice (s >>= f) (t >>= f)@@ -58,6 +57,19 @@ mplus = Choice +instance MonadFix SearchTree where+ mfix f = case fix (f . unOne) of+ None -> None+ One x -> One x+ Choice _ _ -> Choice (mfix (leftChoice . f)) (mfix (rightChoice . f))+ where+ unOne (One x) = x+ unOne _ = error "mfix SearchTree: not One"+ leftChoice (Choice s _) = s+ leftChoice _ = error "mfix SearchTree: not Choice"+ rightChoice (Choice _ t) = t+ rightChoice _ = error "mfix SearchTree: not Choice"+ -- | -- Another search monad based on continuations that produce search -- trees.@@ -74,7 +86,7 @@ fmap f a = Search (\k -> search a (k . f)) instance Applicative Search where- pure = return+ pure x = Search ($ x) (<*>) = ap @@ -84,8 +96,6 @@ (<|>) = mplus instance Monad Search where- return x = Search ($ x)- a >>= f = Search (\k -> search a (\x -> search (f x) k)) instance MonadFail Search where@@ -95,3 +105,6 @@ mzero = Search (const mzero) a `mplus` b = Search (\k -> search a k `mplus` search b k)++instance MonadFix Search where+ mfix f = Search (\k -> mfix (searchTree . f) >>= k)
tree-monad.cabal view
@@ -1,7 +1,7 @@ cabal-version: >=1.10 name: tree-monad-version: 0.3.1+version: 0.3.2 synopsis: Non-Determinism Monad for Tree Search description: This Haskell library provides an implementation of the MonadPlus type class that represents the search space@@ -20,7 +20,7 @@ library exposed-modules: Control.Monad.SearchTree other-extensions: Rank2Types- build-depends: base >=4.13 && <4.15+ build-depends: base >=4.13 && <4.16.3 default-language: Haskell2010 ghc-options: -Wall