[Shootout-list] dispatch

Jon Harrop jon at ffconsultancy.com
Fri Jul 29 17:49:06 UTC 2005


On Friday 29 July 2005 18:07, José Bollo wrote:
> Le vendredi 29 Juillet 2005 07:14, Jon Harrop a écrit :
> > I've just written a few OCaml implementations of the dispatch test. This
> > is another test which computes a trivially reducible expression (the
> > answer is 450N) and, unsurprisingly, a line must be drawn completely
> > arbitrary to determine which implementations are and are not allowed,
> > i.e.
> > "print(450*n)" is probably not allowed.
>
> ooooh ocaml is really good!

I also have an OO version which is much slower and more verbose but there 
really isn't any point in using OO here if you have variants. The SML code 
would be virtually identical to the OCaml and is probably much faster with 
MLton (ocamlopt doesn't in-line the "tag" function through a functor).

> But it is ?maybe? not what is expected.

Yes, I haven't a clue what this is supposed to be testing. In particular, I 
can't see what is required that isn't already in my ray tracer, for example.

> A solution is to replace the constant state's value by parametric ones. The
> values would be given as arguments to the program.
>
> dispatch 1 2 3 4 5 6 7
>
> must give the same result.

Are those the return values of the tag function that you're specifying on the 
command line? If so, then that is easily implemented by creating variables 
"a", "b" ... from the command line arguments and then writing tag functions 
like:

  let tag = function Empty -> a | Full -> b | Sealed -> c

However, the program is still trivially reducible. I think the author tried to 
engage the (IMHO impossible) challenge of finding something which OO is good 
for. The best you can do is subjectively try to enforce the use of OO but, 
then, nobody will agree on what OO is...

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists




More information about the Shootout-list mailing list