--
Daniel C. Sobral
I travel to the future all the time.
Maybe I'm being a bit dim, but why is this preferable to just pimping
away the variance altogether?
scala> :paste
// Entering paste mode (ctrl-D to finish)
class InvariantContains[T, CC[X] <: Seq[X]](xs: CC[T]) {
def invarContains(x : T) : Boolean = xs contains x
}
// Exiting paste mode, now interpreting.
defined class InvariantContains
scala> implicit def invar[T, CC[X] <: Seq[X]](xs: CC[T]) = new
InvariantContains(xs)
invar: [T, CC[X] <: Seq[X]](xs: CC[T])InvariantContains[T,CC]
scala> List(1, 2, 3) invarContains "foo"
<console>:10: error: type mismatch;
found : java.lang.String("foo")
required: Int
List(1, 2, 3) invarContains "foo"
^
Cheers,
Miles
--
Miles Sabin
tel: +44 7813 944 528
gtalk: mi...@milessabin.com
skype: milessabin
g+: http://www.milessabin.com
http://twitter.com/milessabin
http://www.chuusai.com/
Maybe I'm being a bit dim, but why is this preferable to just pimping
away the variance altogether?
Oh, so the idea would be to replace the existing definition of
contains with your one with the type constraint, rather than use that
MyConvariantCollection type (which looks a lot like an intermediate
structure to me)? In which case my only quibble would be that using
=:= rather than <:< would have the same effect and be a bit more
transparent.
In which case my only quibble would be that using
=:= rather than <:< would have the same effect and be a bit more
transparent.
rather than use that
MyConvariantCollection type (which looks a lot like an intermediate
structure to me)?
What will the value of the implicit parameter be? Won't it be a new instance of an identity function?