D is awesome, my situation, questions

mike.benfield at gmail.com mike.benfield at gmail.com
Sat Jun 3 22:55:08 PDT 2006


In article <e5te5l$2l63$1 at digitaldaemon.com>, Jarrett Billingsley says...
>

>Hehe, pattern matching.  Funny you mention that, as there was a brief (read: 
>2-week) period when D had built-in regexp operators 

Actually I was thinking about ML-style pattern matching on constructors
rather than regexps (regexps are cool too but yeah, it makes sense for
them to be in a library).

>And lastly, variant types - I suppose if you're still thinking in 
>"dynamically typed" terms, you'd miss them, but I've never needed anything 
>like them; when thinking in object-oriented terms, anyway, polymorphism is 
>usually more than enough, and when you need something that can accept 
>multiple types, there's templates.  You might also want to look into 
>std.boxer - the Box type is basically a typesafe variant. 

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.

(They also have the same comparison, but with Standard ML vs. C++:

http://www.ffconsultancy.com/free/ray_tracer/comparison_cpp_vs_sml.html

SML trounces the C++ program in performance too, but that's not really
fair since they compiled with it with mlton, a whole program optimizing
compiler.)

Scala does a good job of implementing variant types and pattern matching
in a language that looks more like C++ than ML.





More information about the Digitalmars-d mailing list