Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Question on writing efficient Ocaml.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-12-29 (09:58)
From: Ian Oversby <oversby@h...>
Subject: Re: [Caml-list] Question on writing efficient Ocaml.
>Dear Ian,
>your ocaml code is quite "unusual", and I must say I am not convinced your 
>C++ code is written optimally (but I don't know anything about C++).

I'm not convinced it is optimal either - I wrote the scheme version first
and then translated first into Ocaml and then to C++.  It is my first
piece of Ocaml (and hopefully not the last) which probably accounts for
the unusualness.

>I transcribed your C++ version to a reasonable ocaml version. Please 
>compare what you did with how I transliterated your C++ code (attached file 
> In particular, I use more obvious types (position is just 
>int*int, a board is a 2D array)
>Then I wrote my own ocaml version which mimicks your algorithm, except that 
>instead of creating new boards all the time, it just keeps a list of 
>current positions of queens (attached file

Excellent.  Thanks very much.  I'll have a look at both of them and
see what I can learn.

>By the way, why are you placing 8 queens on the board, no matter how large 
>the board is? I thought the idea was to put n queens on a board of size n x 

Yes, good catch - it is a bug.  I didn't do sufficient testing.


>Feel free to post this on your blog.

Thanks again.  I'll probably write a follow-up when I understand what
is going on.  Jon Harrop also uncovered an algorithmic difference between
the C++ and the Ocaml so I'll look into that too.



MSN Hotmail is evolving – check out the new Windows Live Mail