Resolving LUB of Validation Example

20 views
Skip to first unread message

Kevin Meredith

unread,
Jun 16, 2015, 3:35:41 PM6/16/15
to sca...@googlegroups.com
Why do the following type parameters resolve to a LUB of Any in the following example?

scala> if (true) "foo".success[String] else 1234.failure[Int]
res1: scalaz.Validation[Any,Any] = Success(foo)

I was expecting a result of Validation[String, Int].

Tom Switzer

unread,
Jun 16, 2015, 3:43:07 PM6/16/15
to sca...@googlegroups.com

The type parameter is for the other side - for example, 1234.failure[String] and "ABC".success[Int]

--
You received this message because you are subscribed to the Google Groups "scalaz" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaz+un...@googlegroups.com.
To post to this group, send email to sca...@googlegroups.com.
Visit this group at http://groups.google.com/group/scalaz.
For more options, visit https://groups.google.com/d/optout.

Colt Frederickson

unread,
Jun 16, 2015, 3:44:08 PM6/16/15
to sca...@googlegroups.com
The type in the [ ] is the type param of the opposite type constructor.

scala> "foo".success[Long]
res0: scalaz.Validation[Long,String] = Success(foo)


So you're specifying the type of the failure param when you call .success.

--
Reply all
Reply to author
Forward
0 new messages