module Build.Task.MonadPlus (random, computeND, correctBuildValue) where
import Control.Monad
import Build.Task
import Build.Store
random :: (Int, Int) -> Task MonadPlus k Int
random (low, high) = Task $ const $ foldr mplus mzero $ map pure [low..high]
computePureND :: Task MonadPlus k v -> (k -> v) -> [v]
computePureND task store = run task (return . store)
computeND :: Task MonadPlus k v -> Store i k v -> [v]
computeND task store = computePureND task (flip getValue store)
correctBuildValue :: Eq v => Tasks MonadPlus k v -> Store i k v -> Store i k v -> k -> Bool
correctBuildValue tasks store result k = case tasks k of
Nothing -> getValue k result == getValue k store
Just task -> getValue k result `elem` computeND task store