3 ms·
I think Scala is great as long as you stay on the road and not end up in the deep depths of academic hell (i.e. http://blogs.atlassian.com/2013/01/covariance-an
by mikkelewis 13y ago
I think Scala is great as long as you stay on the road and not end up in the deep depths of academic hell (i.e. http://blogs.atlassian.com/2013/01/covariance-and-contravariance-in-scala/ http://blogs.atlassian.com/2013/01/covariance-and-contravari...).
I should say one thing however:
I'm using Scala because of Akka. An extremely powerful library that does a good job of hiding the complexities while still allowing you to be flexible.
- bcoates 13y agoThat's a gratuitously category-theoretic explanation, all you need to explain covariance and contravariance is is-a. An immutable List of Foos is a List of Bars if a Foo is a Bar. A function taking X and returning Y is a function taking A and returning B if A is a X and Y is a B. It's just answering the question "Can I use type relationships to guarantee that I will have no run-time conversion failures?"
- deleted 13y ago[deleted]
- evincarofautumn 13y agoT is covariant (positive) if A ≤: B ⇒ T<A> ≤: T<B>. T is contravariant (negative) if A ≤: B ⇒ T<B> ≤: T<A> (i.e., the other way around). Pretty simple stuff.
- pkolaczk 13y agoIt is easy to remember if you think of it: + (covariant): the type can be cast to some broader (more general) type - (contravariant): the type can be cast to some narrower (more concrete) type