How to get rollback and I / O using ListT?

I do not know how the List ListT transformer should be used. For example, how this simple task should be performed:

 backtrack :: ListT IO () backtrack = do x <- lift getLine a <- x lift $ print a 

And what type of function should be?

This is not the task I'm trying to accomplish (I know how to solve this problem using many other methods), I just want to know how to use ListT to perform such tasks.

+4
source share
2 answers

Is this what you tried to do?

 import Control.Monad.List backtrack :: ListT IO () backtrack = do x <- ListT getLine lift $ print x 

Example run in GHCi:

 *Main> runListT backtrack foo 'f' 'o' 'o' [(), (), ()] 
+3
source

You should look at ListT done right and the LogicT countdown. In particular, interleave in logic handles infinity better.

+4
source

All Articles