The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Newsgroups: comp.lang.functional
From: Matthew Fluet <mfl...@acm.org>
Date: Thu, 02 Jun 2005 08:35:12 -0400
Local: Thurs 2 Jun 2005 13:35
Subject: Re: Port my ray tracer
> It is interesting to note that the SML is 50% longer than the OCaml. It may be 50% longer than the original 66-line OCaml program, but it seems to be exactly the same size at the optimized OCaml program you posted. > Here is the SML (for Mlton): Just a couple of SML notes: > fun real n = Real.fromInt n A function "real" (of identical semantics) is available in the top-level environment of the Basis Library, so there is no need to define your own version. > val delta = 0.00000001 (* FIXME: Where is mach eps in the std libs? *) The Standard ML Basis Library does have Real.minNormalPos which corresponds to OCaml's min_float. You can compute OCaml's epsilon_float with val epsilon = Real.nextAfter(1.0,2.0) - 1.0 > val infinity = 1.0 / 0.0 (* FIXME: Where is infinity? *) val infinity = Real.posInf > val pi = 4.0 * Real.Math.atan 1.0 (* FIXME: Where is pi? *) val pi = Real.Math.pi > (* 3D vector I don't know if it is typical, but records will have no impact on the > SML typically uses tuples rather than records (as in the OCaml implementation). *) > type vec = real * real * real peformance of the code compiled under MLton (and presumably under other SML compilers). > (* SML allows operator precedences to be declared when defining infix operators. *) Rather than using "+0.0" to force the overloaded operators to resolve to > infix 2 *| fun s *| (x, y, z) = (s*x+0.0, s*y, s*z) > infix 1 +| fun (x1, y1, z1) +| (x2, y2, z2) = > (x1+x2+0.0, y1+y2+0.0, z1+z2+0.0) > infix 1 -| fun (x1, y1, z1) -| (x2, y2, z2) = > (x1-x2+0.0, y1-y2+0.0, z1-z2+0.0) > fun dot (x1, y1, z1) (x2, y2, z2) = x1*x2 + y1*y2 + z1*z2+0.0 Real.real, you could use a simple type annotation on the functions: fun s *| (x, y, z) : vec = (s*x, s*y, s*z) MLton doesn't actually perform constant folding on floating point You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||