{-# LANGUAGE FlexibleContexts #-} module Strategies where import Control.Monad import Base import Representations -- -------------------------------------- -- Strategies -- -------------------------------------- -- Same monad to that in the SYB3 paper data S m a = S a (m a) instance MonadPlus m => Monad (S m) where return x = S x mzero (S x xs) >>= k = S r (rs1 `mplus` rs2) where S r rs1 = k x rs2 = do x <- xs let S r _ = k x return r -- Apply f to one of the immediate children of x one :: (GMap (PF a), PFView a, Functor m, MonadPlus m) => (a -> m a) -> a -> m a one f x = fmap to rs where S _ rs = fmapM try (from x) try x = S x (f x) -- Apply f once to one of the immediate children of x once :: (GMap (PF a), PFView a, Functor m, MonadPlus m) => (a -> m a) -> a -> m a once f x = f x `mplus` one (once f) x