[mercury-users] Request for comments on this code

Ralph Becket rafe at cs.mu.OZ.AU
Tue Jul 4 10:44:36 AEST 2006


Nicolas Pelletier, Monday,  3 July 2006:
> Hello,
> 
> the following code  solves the  N  queens problems using a  constraint
> based approach. It  is a rather direct  port from a  Prolog program. I
> wrote this program  as an exercise  in learning Mercury concepts,  and
> would like other  mercury users to tell  me  what they think  could be
> improved: is  the style right  ? is there  a better  strategy to write
> this kind of algorithm ?

The style is about right, although it's usually better style to order
your predicates top-down rather than bottom-up (e.g., put queens near
the start).

Using vanilla, non-constraint solver Mercury code, there are, of course,
more efficient ways to do this, but they require more coding.

Using a finite domain solver module (which we have implemented as part
of the G12 project, but which hasn't yet been made available to the public),
the code would look very similar to what you've written and should run
very efficiently.

> For the record, the attached code is  not blindingly fast, but it only
> uses native Mercury constructs (as opposed to calling some optimized C
> code through FFI).

As I say, it is possible to code up an efficient Mercury version of
queens without using solver types.

-- Ralph
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list