What do you think about Mercury?

Marcin 'Qrczak' Kowalczyk qrczak@knm.org.pl
9 Apr 2001 13:40:42 GMT


Mon, 9 Apr 2001 14:30:01 +1000, Fergus Henderson <fjh@cs.mu.oz.au> pisze:

> 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