Variance of Getter type parameters

20 views
Skip to first unread message

Maciej Biłas

unread,
Dec 18, 2014, 11:35:03 AM12/18/14
to scala-...@googlegroups.com
Hi,

I hope you don't mind with a question about the basics of the library. I'm only now familiarising myself with the Optics concepts and Monocle library.

One thing that came to my attention is that the type parameters of the Getter class are invariant. Why don't they follow the variance of Function1 (source being contravariant and target covariant)? I could imagine passing a a Getter[CharSequence, Int] to a function that accepts Getter[String, Any]. It's not possible, though.


Thanks!

-Maciej

Julien Truffaut

unread,
Dec 19, 2014, 6:18:21 AM12/19/14
to scala-...@googlegroups.com
Hi Maciej,

No I don't mind at all, that's in fact the goal of this mailing list :)

Nothing use variance in Monocle mostly because I find it extremely difficult to reason about and it is simple to get it wrong. On top of that you can use Iso to define the relation between CharSequence and String (is it correct to say that you can go back and forth from these 2 types?).

So If you have a Getter g of type Getter[String, A] and an Iso i of type Iso[CharSequence, String] then you can define a Getter[CharSequence, A] with i composeGetter g
Reply all
Reply to author
Forward
0 new messages