Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 19:28

    SethTisue on 2.13.x

    2.12: new Scala SHA 2.12: update expected-failure l… add akka-http-webgoat (#1017) and 1 more (compare)

  • 19:08

    SethTisue on 2.11.x

    sbt version bump (1.3.3->1.3.4)… 2.12: new Scala SHA 2.12: update expected-failure l… and 3 more (compare)

  • 19:04
    SethTisue commented #8545
  • 19:03
    som-snytt commented #11824
  • 18:54
    som-snytt labeled #11824
  • 18:54
    som-snytt commented #11824
  • 18:46
    som-snytt review_requested #8591
  • 18:46
    scala-jenkins milestoned #8591
  • 18:46
    som-snytt opened #8591
  • 18:38
    SethTisue milestoned #3237
  • 18:38
    SethTisue assigned #9386
  • 18:38
    SethTisue milestoned #9386
  • 15:21
    som-snytt commented #8590
  • 14:50
    lrytz commented #8588
  • 13:12

    lrytz on 2.13.x

    Avoid length of list Lint confusing by-name conversi… Lint by-name conversion of bloc… and 1 more (compare)

  • 13:12
    lrytz closed #8590
  • 13:12
    lrytz closed #9386
  • 13:12
    lrytz closed #3237
  • 09:36
    dwijnand commented #1016
  • 09:32
    dwijnand commented #1008
Rob Norris
@tpolecat
I feel like I’m taking crazy pills. I had a different random automation failure yesterday.
I need to switch to a language nobody uses so I won’t have to worry about this stuff.
I guess I could try Mill. @lihaoyi is there a way to run paradox and push stuff to gh-pages?
Luis Miguel Mejía Suárez
@BalmungSan

Hi,

I have something like this:

trait Factory[F[_]] {
  type R[A]
  def create[A](a: => A): R[A]
}

object Factory {
  type Aux[F[_], _R[_]] = Factory[F] { type R[A] = _R[A] 

  type Id[A] = A

  implicit val FutureFactory: Factory.Aux[Future, Id] =
    new Factory[Future] {
      override final type R[A] = A
      override final def create[A](a: => A): A = a
    }
}

object Driver {
  def driver[F[_]]: DriverPartiallyApplied[F] = new DriverPartiallyApplied(dummy = true)

  private final class DriverPartiallyApplied[F[_]](private val dummy: Boolean) extends AnyVal {
    def apply[R[_]](uri: String)(implicit F: Factory.Aux[F, R]): R[Driver[F]] =
      F.create(...)
  }
}

Now, on another project I would like to do this:

val driver: Driver[Future] = Driver.driver[Future]("uri")

But that does not compile with this error:

found: [R[_]]R[neotypes.Driver[scala.concurrent.Future]]
required: neotypes.Driver[scala.concurrent.Future]

If I leave out the explicit type signature, it works as expected. The compiler is able to figure out latter that driver is a Driver[Future].

Anyone knows how can I fix that?

Hanns Holger Rutz
@Sciss

Is it possible to define "negative implicits", like

trait Ex[+A]
case class Const[A](value: A) extends Ex[A]

implicit def const[A](x: A): Ex[A] = Const(x)

such that const cannot be called when A <: Ex[_] ? I have no way to put an upper bound on A, e.g. it could be Int, String, java.io.File, ... types over which I have no control.

Luis Miguel Mejía Suárez
@BalmungSan
@Sciss Can not test it right now, but I believe you can use Shapeless =:!=.
Something like implicit def const[A](x: A)(implicit ev: A =:!= Ex[_]): Ex[A] = Const(x)
Hanns Holger Rutz
@Sciss
sounds good, I wonder how that's implemented. Of course can't google =:!=, any pointer to the relevant documentation?
must be a macro, I guess?

Perhaps easier solution would be if I have

   def runWith(map: Ex[Map[String, _]]) = ???

but I need to restrict the value types in the map, for example by coming with a type class; the problem being that the value types may vary (it's a heterogeneous map, Scala's arch enemy)

Hanns Holger Rutz
@Sciss
So I want a Map[String, Int] to be able to be lifted, but not Map[String, Ex[_]].
So perhaps a simpler question is, "how can I place constraints on the value types of a heterogeneous map", with emphasis on the user being able to type it with literals without the need to use type ascriptions etc.

For instance:

def title: Ex[String]

trait Runner {
  def runWith(attr: Ex[Map[String, _]]): Unit
}

def r: Runner

r.runWith(Map("foo" -> 123, "bar" -> title))

and what I need to enforce is the expansion

Map(Const("foo") -> Const(123), Const("bar") -> title)

and prevent

Const(Map("foo" -> 123, "bar" -> title /* bad */))
Hanns Holger Rutz
@Sciss
I have the hunch that I should introduce trait ExMap[K, V] extends Ex[Map[K, V]] so that I can restrict lifting from Map constructor.
Hanns Holger Rutz
@Sciss
Like how can I get rid of the : Ex[String] annotations here:
trait ExMapTest3 {
  trait Ex[+A]

  implicit def const[A](in: A): Ex[A]

  implicit def liftMap[K, V](m: Map[Ex[K], Ex[V]]): ExMap[K, V]

  trait ExMap[K, V] extends Ex[Map[K, V]]

  def runWith(m: ExMap[String, Any]): Unit

  def title: Ex[String]

  runWith(
    Map(("foo": Ex[String]) -> ("bar": Ex[String]))  // not nice
  )

  runWith(
    Map(("foo": Ex[String]) -> title)
  )
}
Hanns Holger Rutz
@Sciss

I guess the best would be to just surrender to

implicit def const[A: Permitted](in: A): Ex[A]

and give dozens of type classes for all primitives etc.; perhaps I could use marker trait scala.Immutable for types I control.

Hanns Holger Rutz
@Sciss

along these lines

  implicit def const[A: Value](x: A): Ex[A] = Const(x)

  object Value {
    implicit object anyVal    extends Value[AnyVal  ]
    implicit object string    extends Value[String  ]
    implicit object file      extends Value[File    ]
    implicit object spanLike  extends Value[SpanLike]

    implicit def tuple  [A: Value, B: Value]: Value[(A, B)] = null

    implicit def option [A: Value]: Value[Option[A]] = null
    implicit def seq    [A: Value]: Value[Seq   [A]] = null
  }
  trait Value[-A]

0: Ex[Int]  // ok
Some("foo"): Ex[Option[String]]  // ok
Some("foo": Ex[String]): Ex[Option[Ex[String]]]   // forbidden

Is there any issue with = null? Would like to avoid instantiations for throw away witnesses.

Luis Miguel Mejía Suárez
@BalmungSan
@Sciss Sorry, I had to go for a while. I am a little lost right now. What is your ultimate goal?
I think, at the end, you only want that the runWith method only be called with a Map[String, _] where you have a subset of what is valid for the values. Am I right?
Hanns Holger Rutz
@Sciss
Yes. I think I will try with the last approach, even if it means adding a lot of third-party dummy type class instances.
it's just annoying having to add lots of import statements after a while to bring them into scope. I think there is some plan to introduce export primitives or so into Scala in the future.
Luis Miguel Mejía Suárez
@BalmungSan
Do you expect the Map to always be a literal?
Hanns Holger Rutz
@Sciss
definitely not. There could be other sources producing Ex[Map] which are not constant.
Luis Miguel Mejía Suárez
@BalmungSan
Uhm, I was about to propose a Macro, but now it does not make sense.
Hanns Holger Rutz
@Sciss
yeah, I'd rather avoid them
Fabio Labella
@SystemFw

@Sciss

sounds good, I wonder how that's implemented. Of course can't google =:!=, any pointer to the relevant documentation?

In case you're still interested, this is the implementation for <:!< and =!:=

def unexpected : Nothing = sys.error("Unexpected invocation")

  // Type inequalities
  trait =:!=[A, B] extends Serializable

  implicit def neq[A, B] : A =:!= B = new =:!=[A, B] {}
  implicit def neqAmbig1[A] : A =:!= A = unexpected
  implicit def neqAmbig2[A] : A =:!= A = unexpected

  @scala.annotation.implicitNotFound("${A} must not be a subtype of ${B}")
  trait <:!<[A, B] extends Serializable

  implicit def nsub[A, B] : A <:!< B = new <:!<[A, B] {}
  implicit def nsubAmbig1[A, B >: A] : A <:!< B = unexpected
  implicit def nsubAmbig2[A, B >: A] : A <:!< B = unexpected

it basically encodes negation via absurd. Let's pick =:!= for example, <:!< works the same: instead of providing an implicit instance when type A is not equal to B, it provides an instance that is valid for any two A and B (neq), and then two instances that are valid when A == B (neqAmbig1 and neqAmbig2). So, if you ask for Int =!:= String , new is the only relevant instance, and things compile. If you ask for Int =!:= Int, the compile finds both neqAmbig1 and neqAmbig2 at higher specificity than neq, but same specificity wrt to each other, so compilation fails when two types are equal, which is the desired semantics

Hanns Holger Rutz
@Sciss
@SystemFw thanks for the explanation, good to know it works without macros
Rob Norris
@tpolecat
@ def notInt[A](a: A)(implicit ev: A =:!= Int): A = a 
defined function notInt

@ notInt("foo") 
res3: String = "foo"

@ notInt(3) 
cmd4.sc:1: ambiguous implicit values:
 both method neqAmbig1 in package shapeless of type [A]=> A =:!= A
 and method neqAmbig2 in package shapeless of type [A]=> A =:!= A
 match expected type Int =:!= Int
val res4 = notInt(3)
                 ^
Compilation Failed

@ def foo[A](a: A): A = notInt(a) 
defined function foo

@ foo(1) 
res5: Int = 1
It's really easy to defeat the type inequality constraint. Just FYI.
Hanns Holger Rutz
@Sciss
!
Jon Pretty
@propensive

@saifjsl I think @propensive still has Scala 2.6 in production somewhere. People are reluctant to destabilize codebases just for the sake of keeping up to date.

Confirmed. I have a Scala 2.6.1 web application which runs for about a month each year. My client keeps paying me more each year to keep it running. My biggest concern isn't so much the Scala 2.6.1 compiler but the shoddy coding practices I used extensively in about 2007.

Dale Wijnand
@dwijnand
It would be interesting to see that code. Maybe you can anonymise it and open-source it, somehow?
Otto Chrons
@ochrons
I cannot make it to Scala World this year, so my early bird ticket is FOR SALE. Conference ticket + Functional Frenzy workshops, 395€ (VAT 0%). Conference info https://scala.world/ (it's by far the best Scala conference in rural England! :stuck_out_tongue_winking_eye: )
Oscar Vargas Torres
@oscarvarto
Hi! Is there a simple way to make scalac report a warning for methods that are undefined (using ???)?
For example, in the following snippet:
def bar(x: Int): Int = ???
Martijn Hoekstra
@martijnhoekstra
Not that I know of. A workaround could be having something like @deprecated("Undefined method") def ????: Nothing = ??? and they'll show up in your deprecation warnings
it's a good idea to have an option to warn on ??? in the compiler IMO
even though generally I don't think building knowledge of the stdlib into the compiler is usually a good idea
it sounds like a fun project tbh
Josef
@Josef-Vonasek

Any idea how to resolve this type inference bug? :

def foo[T, X <: XX[T]](x: X): X = macro fooMacro[T, X]

def fooMacro[T, X<: XX[T]](c: Context)(x: c.Expr[X]): c.Expr[X] = ...

Error:(9, 11) macro implementation has incompatible shape: ...
type arguments [Nothing,X] do not conform to method fooMacro type parameter bounds [T,X<: XX[T]]>

Oscar Vargas Torres
@oscarvarto
@martijnhoekstra Thanks for replying! I once spent some time chasing for a bug caused by an unimplemented method (I forgot to implement that method)
Deepak Singh
@dpk3d
Guys Can someone help me converting Seconds = 7500s into 2h5m0s..?
Deepak Singh
@dpk3d

def solution(n: Int): String = {
// write your code in Scala 2.12
var s = n % (24 * 3600)

val m = (n / 60 ) % 60

val h = (n / 60 / 60 ) % 24

s = s % 60

val strin = "%2dh%2dm%2ds".format(h, m, s).stripMargin

return strin

this solution is giving me space I need in hhmmss
Otto Chrons
@ochrons
replace %2d with %d
also var s = n % (24 * 3600) is unnecessary, simple val s = n % 60 works
Deepak Singh
@dpk3d
@ochrons got 2h 5m0s but my expected is 2h5m0s
Deepak Singh
@dpk3d

I have a string S = "00-44 48 555 8361"

And I want to format the string that digits are grouped in blocks of length three separated by - dash . Final block can be two digits.

Expectation is "004-448-555-583-61"

Can someone gives me heads up on this

Josef
@Josef-Vonasek
in pseudocode: S.filter(!_.inside("- ")).groupBy3.mkString("-")
Deepak Singh
@dpk3d

I've done in Python
Can someone convert in Scala

Solution

ph = "00-44 48 5555 8361"

def normalize(ph):
tmp = []
final_str = ""
index = 0
while( index < len(ph)):
if ph[index] == ' ' or ph[index] == '-':
index +=1
continue
tmp.append(ph[index])
if len(tmp) == 3:
str = ""
final_str = final_str + '-' +str.join(tmp)
tmp = []
index+=1
str = ""
final_str = final_str + '-' +str.join(tmp)
final_str = final_str.lstrip("-").rstrip("-")
return final_str

print (ph)
print (normalize(ph))

Andriy Plokhotnyuk
@plokhotnyuk
s.filter(_.isDigit).sliding(3, 3).mkString("-")
Josef
@Josef-Vonasek
^ or this :D