ALGOL68-like union type switches?

Reiner Pope reiner at none.com
Fri Apr 6 19:43:45 PDT 2007


To a limited extent, this has been implemented for C++: based on 
Andrei's Generic<Programming> column (in three parts):
http://www.ddj.com/dept/cpp/184403821
http://www.ddj.com/dept/cpp/184403828
http://www.ddj.com/dept/cpp/184403834
The ideas were then implemented at boost::variant:
http://www.boost.org/doc/html/variant.html

There's a much cooler implementation of this in a lot of functional 
languages; see http://en.wikipedia.org/wiki/Algebraic_data_type for 
examples. The pattern matching goes beyond types into a whole lot of 
other things.

I've also tried to implement some kind of thing like this in D with 
mixins and CTFE. It's still a work-in-progress; getting the right 
balance between a nice user-side syntax and not too much details on the 
implementation side is hard. Also, the inability to do variadic 
templates like Variant!("string", type, "string2", type2, "string3", 
type3) is really painful -- mixing types and values doesn't work -- bug 
#586. Also, the alluring AST macros "just round the corner" make it hard 
to spend time on string parsing when a much nicer implementation could 
be possible in the near future. ;P

Cheers,

Reiner



More information about the Digitalmars-d mailing list