A backtracking logic programming monad (http://code.haskell.org/~dolio/)
#1MonadLogic WriterT instance don't satisfy reflect law
code:
import Control.Monad
import Control.Monad.Writer.Strict
import Control.Monad.Logic
hoge :: WriterT [Int] [] Int
hoge = WriterT $ [ (185471556, [-1449817595]) ]
fuga :: WriterT [Int] [] Int
fuga = WriterT $ [ (-884160399, [0]) ]
piyo :: WriterT [Int] [] Int
piyo = hoge `mplus` fuga
main = do
print piyo
print $ (msplit piyo >>= reflect)
output:
WriterT [(185471556,[-1449817595]),(-884160399,[0])]
WriterT [(185471556,[-1449817595]),(-884160399,[-1449817595,0])]
Having looked at the instances, I think this is impossible to fix. The question is whether the WriterT instances should be removed, or the law should be noted as not a law.
I believe the law simply isn't a law, at least for now. In particular, the
msplit
laws only pin down howmsplit
behaves on values built by "consing" withmplus
andmzero
. This says an awful lot about[]
and I believe alsoLogic
, but much less about other instances. Either themsplit
laws need to be strengthened, thereflect
law needs to be weakened, or both. I have essentially no intuition whatsoever about what aMonadLogic
is supposed to act like, so I have no particular opinion on this as yet.