Jeśli jesteś właścicielem tej strony, możesz wyłączyć reklamę poniżej zmieniając pakiet na PRO lub VIP w panelu naszego hostingu już od 4zł!

HHVM Blog: Covariance, Contravariance, and super Type Constraints

HHVM Blog: Covariance, Contravariance, and super Type Constraints

The HHVM blog has a new post that talks about covariance, contravariance, and super type constraints – enhancements to the previous generics handling in the Hack language.

Hack has recently enhanced its generics with two features: variance annotations and super type constraints. In this post, I’ll explain how they work and why they were added.

They start with variance and how the idea of covariance (consistent type variance in class parameters) fits in. They include a code example showing how this typing works and some of the issues with following this covariance flow. Following this they talk about contravariance, the opposite of covariance, where the typing can be used as a parameter type but not a return type. They go on to talk about the idea of “super type constraints” and how they augment the current type constraint handling to provide improved type resolution. They end the post with a bit about how “super” relates to “as” constraints and a historical note about some hard-coded class names that are always resolved as either co- or contravariant by the typechecker.

Link: http://hhvm.com/blog/9215/covariance-contravariance-and-super-type-constraints
Source: http://www.phpdeveloper.org/news/22766

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Posted Maj 31st, 2015 in WEB and PHP Development.

Leave a response: