I just fiddled with Tony Morris's excellent catamorphism exercise when I reflected on what was happening in the following situation ..
def cata[X](some: A => X, none: => X): X
Let me now name this method as follows:
def isDefined: Boolean = cata( _ => true, false)
I was wondering if the inferencer type defines the type _ => true as A => Boolean or Any => Boolean . Due to the fact that Function1 is contravariant in its input parameter, both of the following compile just fine:
def isDefined: Boolean = cata( (_: A) => true, false) //
So the question is, is the inferencer type suitable for # 1 or # 2?
scala type-inference catamorphism
oxbow_lakes
source share