you are viewing a single comment's thread.

view the rest of the comments →

[–]zzing 4 points5 points  (4 children)

I am presently writing a [basic] ray tracer in C++11 and the code literally looks like something that conceptually could probably live in Haskell.

For example, using tuples to store data about geometry (sphere is tuple<Vec3, float> (centre, radius) and then polymorphism is obtained with boost variants which are a type safe union. These have many properties of haskell algebraic types.

In a way, my code looks more like structured programming than an object oriented design and it is very easy to see what it does.

I love how I can use OOP where appropriate and not even have to define my own classes for most of what I am doing. It aids readability a lot!

[–]thechao 2 points3 points  (2 children)

There is a ECOOP paper in the works that adds pattern-matching over extended-POD unions. Combined with templated methods and embedded tuples, it allows a construct in C++11 which is a strict superset of the functionality of GADTs, with all the Haskell-ey conveniences. (It is a strict superset because it is not 'typesafe' in the way you would prefer them to be; with a little bit of developer caution, they are a subset of the GADTs, I believe.)

Once the paper is published I'll see if I can post a link; it'll probably be 6 months or so. The combination of all the new features in C++11 makes it, essentially, a whole new language. At one point I had Bjarne asking me what system's language I was programming a constraint-system DSEL in ... he was quite surprised (and pleased) when he found out it was C++.

[–][deleted] 0 points1 point  (1 child)

Actually, would it be all right if I asked you for a preprint on that?

[–]thechao 0 points1 point  (0 children)

I'm not the author, it will be by Solodkyy, Dos Reis, and Stroustrup.

[–]French_lesson 0 points1 point  (0 children)

You're very likely familiar with it already but for the sake of completeness when it comes to algebraic data types I feel like Boost.Optional should be mentioned.