Last night, in response to this question , I noticed the following:
scala> val foo: Option[Set[Int]] = Some(Set(1, 2, 3)) foo: Option[Set[Int]] = Some(Set(1, 2, 3)) scala> import scalaz._, Scalaz._ import scalaz._ import Scalaz._ scala> foo.sequenceU res0: scala.collection.immutable.Set[Int] = Set(1, 2, 3)
That is, if foo is an optional set of integers, then sequencing returns a set of integers.
This is not what I expected at the beginning, since the sequence F[G[A]] should return G[F[A]] (assuming that F is passing and G is an applicative functor ). In this case, the Option layer just disappears.
I know that this probably has something to do with some interaction between one of the Set supertypes and the Unapply machine that does the sequenceU work, and when I can find a few minutes, I plan to work through the types and write a description of what happens .
This seems like a potentially interesting little puzzle, and I thought I'd post it here if someone could defeat me before the answer.
types scala scalaz scalaz7
Travis brown
source share