News for hackers. Stuff that matters.
Re:Type Erasure with Merged Concepts in C++ by jonsterling on Sunday October 19, 2014 @09:54PM (#8480403)
I am very confused by the definition of type erasure which is being used in this work.

As a type theorist, my working definition is "terms which have types inside them are turned into terms which do not have types inside them"; this is a process which occurs after types have been checked/inferred, and before execution. This is crucially not something that programmers do: if you take a polymorphic interface and wrap it up in one that doesn't quantify over types, that wasn't type erasure.

But perhaps I have simply misunderstood the code in this post; I'll admit it's been a while since I have read C++.

Re:Type Erasure with Merged Concepts in C++ by subb on Monday October 20, 2014 @12:12AM (#8480672)
When I frist saw the title of Zach Laine's talk, I was confused too. Type erasure for me is what happens with generics in Java, i.e. type information is discarded after compilation. In this case, the type is still present at runtime. I saw this technique described as "type safe void*", which is paradoxal to me. However, I do get the idea behind this, but I think "type erasure" is a wrong name for it.
Re:Type Erasure with Merged Concepts in C++ by jonsterling on Monday October 20, 2014 @01:19AM (#8480789)
Yes, I think this stuff has nothing to do at all with type erasure. it's very confusing when a well defined concept gets appropriated for something that is very different, and totally unrelated.
Re:Type Erasure with Merged Concepts in C++ by Sharlin on Monday October 20, 2014 @07:17AM (#8481529)
Not sure about its exact origins, but in the C++ context the usage is pretty well established. AFAIK it was first used to denote the way std::function (then boost::function) is able to hide the actual type of a callable object while retaining type safety.
Re:Type Erasure with Merged Concepts in C++ by fish2000 on Sunday October 19, 2014 @06:49PM (#8479915)
This is pretty awesome – I’m writing a Python extension in C++ that piggybacks on top of NumPy dtype codes, and I thought that I could “just” use templates to deal with dynamic typing. It proved to be waaaay less straightforward than that, and I had to hack through a lot of stuff with cumbersome macros, and wound up with a gigantic binary image as a result. Actually doing type erasure in C++ (which type erasure, as I understand, is like de rigueur in Java) cuts through all of that cruft… and so, to the refactormobile! Yes.
Re:Type Erasure with Merged Concepts in C++ by infinite8s on Sunday October 19, 2014 @07:19PM (#8479978)
Care to blog about your refactor? I can sort of see how you could use type erasure combined with numpy dtypes but it would be great to see a concrete example.
Re:Type Erasure with Merged Concepts in C++ by vikiomega9 on Sunday October 19, 2014 @05:45PM (#8479747)
Noob question here. In a dynamic language, say python, would duck typing solve the greet_tom problem described here?
Re:Type Erasure with Merged Concepts in C++ by sonyandy on Sunday October 19, 2014 @05:59PM (#8479791)
In C++, duck typing (structural typing) could be represented explicitly using type erasure (explicit in how you have to declare what the structure is) or using templates, which do not require declaration of the structure beyond the actual use in code (though concepts allow you provide structure requirements). Templates result in code being generated for each set of template arguments used. Type erasure does not - or at least not nearly as much (the constructors of the type-erased type almost certainly use templates). In this way, the type erasure approach most closely resembles the behavior of Python (virtual calls), while the template approach most closely resembles the style of Python (no declaration of structure required). There is no ideal way to get both the behavior and style of Python, but you can get pretty close by passing only one type of type-erased type to a function template - only one template function will be produced, which would make calls to virtual functions.
Re:Type Erasure with Merged Concepts in C++ by vikiomega9 on Sunday October 19, 2014 @06:07PM (#8479815)
Amazing, advanced C++ is simply beautiful :P It is very interesting to learn about the hoops static type checking has to jump through.