D is awesome, my situation, questions

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Jun 4 12:41:06 PDT 2006


<mike.benfield at gmail.com> wrote in message 
news:e5tsjs$70p$1 at digitaldaemon.com...

> I think we may mean different things by variant types also. The variant 
> types
> I'm talking about are a feature of statically typed languages like ML, 
> Haskell,
> and Scala. They're somewhat like unions but are type safe and very 
> convenient
> to use (in conjunction with pattern matching). Flying Frog Consultancy has 
> a
> comparison of a ray tracer implementation in OCaml vs. C++:
>
> http://www.ffconsultancy.com/free/ray_tracer/comparison.html
>
> See how much more verbose the C++ is, partially because of the necessity
> to use the C++ object oriented features to express what variant types
> express more concisely.

Hmm.  Well, coming from a purely procedural background, I can say right away 
that the OCaml is certainly more _cryptic_ than the equivalent, more 
verbose, C++ (I especially don't get the 'in' at the end of every other 
line).  But reading the step-by-step comparison underneath helped somewhat.

I think the core of the issue was in the "type scene" line, and in the 
"intersect" function.  The writers tout the ability of OCaml to define a 
type which can be one of several types, and then use a function which 
automatically chooses the correct implementation based on the type of the 
variant.  I really don't see how this is at all elegant - I don't know what 
kinds of capabilities OCaml has for dynamic dispatch (I know it's 'O' for 
'object' but I don't know how it implements that), but what if you had 
twenty types that "derived" from scene?  The "type scene" would then become 
humongous, as well as the implementation of the "intersect" function.  That, 
to me, looks more like tagged unions, which are a poor approximation of OO 
at best.

As I stated in another post, I'm also keen on using up a little more space 
in the name of clarity.  While the C++ is more verbose, it's (in general) 
more readable.  I mean, I saw _this_:

let level = match Sys.argv with [| _; l |] -> int_of_string l | _ -> 6 in

I don't know what to do with that.  It probably translates into several 
lines of C++ code, but at least I'd (and other, newer programmers as well) 
be able to read it and know what it does very quickly.  But this, I think, 
is just more of a consequence of the differences between functional and 
procedural languages. 





More information about the Digitalmars-d mailing list