Details

      Description

      It is possible to convince a type variable to appear as an actual type. I'm not sure how else to describe it:

      
      scala> :pa
      // Entering paste mode (ctrl-D to finish)
       
      sealed abstract class \/[+A, +B]
      final case class -\/[+A](a: A) extends (A \/ Nothing)
      final case class \/-[+B](b: B) extends (Nothing \/ B)
       
      object \/ {
       
        def left[A, B]:  A => A \/ B = -\/(_)
        def right[A, B]: B => A \/ B = \/-(_)
       
        def fromEither[A, B](e: Either[A, B]): A \/ B =
          e fold (left, right)
       
      }
       
      implicit class EitherOps[A, B](self: Either[A, B]) {
        final def disjunction: A \/ B = \/ fromEither self
      }
       
       
      // Exiting paste mode, now interpreting.
       
      defined class $bslash$div
      defined class $minus$bslash$div
      defined class $bslash$div$minus
      defined module $bslash$div
      defined class EitherOps
       
      scala> Left(1).disjunction
      res0: \/[Int,B] = -\/(1) // what the hell is B?
       
      scala> Right(1).disjunction
      res1: \/[A,Int] = \/-(1)
       
      scala> Right(1).disjunction : Nothing \/ Int
      <console>:15: error: type mismatch;
       found   : \/[A,Int]
       required: \/[Nothing,Int]
                    Right(1).disjunction : Nothing \/ Int
      
      

        Issue Links

          Activity

          Hide
          Jason Zaugg added a comment -

          Thanks for the small bug report. The bug seems specific to inferred type arguments of implicit views. It is also present in Scala 2.11.0-M6. I'll take a look at what's going on.

          scala> Left(1)
          res8: scala.util.Left[Int,Nothing] = Left(1)
          
          scala> EitherOps(res8)
          res9: EitherOps[Int,Nothing] = EitherOps@c60090d
          
          scala> EitherOps(res8).disjunction
          res10: \/[Int,Nothing] = -\/(1)
          
          scala> res8.disjunction
          res11: \/[Int,B] = -\/(1)
          
          Show
          Jason Zaugg added a comment - Thanks for the small bug report. The bug seems specific to inferred type arguments of implicit views. It is also present in Scala 2.11.0-M6. I'll take a look at what's going on. scala> Left(1) res8: scala.util.Left[Int,Nothing] = Left(1) scala> EitherOps(res8) res9: EitherOps[Int,Nothing] = EitherOps@c60090d scala> EitherOps(res8).disjunction res10: \/[Int,Nothing] = -\/(1) scala> res8.disjunction res11: \/[Int,B] = -\/(1)
          Hide
          Rob Norris added a comment -

          I don't know if it's relevant, but the problematic expressions also do not reify. Using scalaz as a library you get

          scala> reflect.runtime.universe.reify { Left(1).disjunction }
          <console>:17: error: macro has not been expanded
                        reflect.runtime.universe.reify { Left(1).disjunction }
                                                 ^
          

          and using the REPL example you get

          scala> reflect.runtime.universe.reify { Left(1).disjunction }
          <console>:15: error: this type parameter must be specified
                        reflect.runtime.universe.reify { Left(1).disjunction }
                                                 ^
          
          Show
          Rob Norris added a comment - I don't know if it's relevant, but the problematic expressions also do not reify. Using scalaz as a library you get scala> reflect.runtime.universe.reify { Left(1).disjunction } <console>:17: error: macro has not been expanded reflect.runtime.universe.reify { Left(1).disjunction } ^ and using the REPL example you get scala> reflect.runtime.universe.reify { Left(1).disjunction } <console>:15: error: this type parameter must be specified reflect.runtime.universe.reify { Left(1).disjunction } ^
          Show
          Jason Zaugg added a comment - https://github.com/scala/scala/pull/3088

            People

            • Assignee:
              Jason Zaugg
              Reporter:
              Rob Norris
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development