Created
February 9, 2011 21:33
-
-
Save ghulette/819335 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Strategy where | |
type Strategy m a = a -> m (Maybe a) | |
success :: Monad m => Strategy m a | |
success = return . Just | |
failure :: Monad m => Strategy m a | |
failure _ = return Nothing | |
--These needs "try" or some way to ignore the side-effects | |
test :: Monad m => Strategy m a -> Strategy m a | |
test s x = do | |
mbx' <- s x | |
case mbx' of Just _ -> return (Just x) | |
Nothing -> return Nothing | |
neg :: Monad m => Strategy m a -> Strategy m a | |
neg s x = do | |
mbx' <- s x | |
case mbx' of Just _ -> return Nothing | |
Nothing -> return (Just x) | |
seqn :: Monad m => Strategy m a -> Strategy m a -> Strategy m a | |
seqn s1 s2 x = do | |
mbx' <- s1 x | |
case mbx' of Just x' -> s2 x' | |
Nothing -> return Nothing | |
choice :: Monad m => Strategy m a -> Strategy m a -> Strategy m a | |
choice s1 s2 x = do | |
mbx' <- s1 x | |
case mbx' of Just x' -> return (Just x') | |
Nothing -> s2 x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment