http://hackage.haskell.org/packages/archive/logict/latest/doc/html/Control-Monad-Logic.html
リストモナドの一般化としてLogicTというものがあり、バックトラックを表現できるらしい。
いくつかの自明な例を作ってみた。
import Control.Monad
import Control.Monad.Logic
fromList :: [a] -> Logic a
fromList xs = logic $ \f x -> foldr f x xs
toList :: Logic a -> [a]
toList = observeAll
main = do
print $ toList $ return 42 -- [42]
print $ toList $ fromList [0,1,2] >>= \x -> [x + 1, x + 2, x + 3] -- [1,2,3,2,3,4,3,4,5]
print $ toList $ mzero -- []
print $ toList $ fromList [0,1,2] `mplus` fromList [7,8,9] -- [0,1,2,7,8,9]