
9 Apr
2001
9 Apr
'01
9:40 a.m.
Mon, 9 Apr 2001 14:30:01 +1000, Fergus Henderson
For an example of this, I've attached a program for solving the 8-queens problem;
Here is mine, also using the list monad together with the state monad (uses StateT [] and not ListT State, so the state is restored during backtracking and not permanent). import Monad;import MonadState;main=mapM_(\s->mapM_ putStrLn$[]:[take 8$replicate i '.'++'Q':repeat '.'|i<-s])$evalStateT(mapM(\i->msum[do (/)<-get;guard$i/j;put(\x y->y/=j&&x+y/=i+j&&x-y/=i-j&&x/y);return j |j<-a])a)(\_ _->True);a=[0..7] -- __("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTÊPCZA QRCZAK