logo
down
shadow

Difference between def m(p: T forSome {type T} and def m1(p:Any), is there any ? Explanation needed based on Scala Langu


Difference between def m(p: T forSome {type T} and def m1(p:Any), is there any ? Explanation needed based on Scala Langu

By : user2956882
Date : November 22 2020, 03:03 PM
To fix the issue you can do The type of the expression p in p.toString is the skolemization of T forSome {type T}, per SLS section 6.1:
code :


Share : facebook icon twitter icon
What is the forSome keyword in Scala for?

What is the forSome keyword in Scala for?


By : Ryan Thomas
Date : March 29 2020, 07:55 AM
should help you out The forSome keyword is used to define existential types in Scala. There's this Scala glossary page explaining what they are. I couldn't find a place in the Scala docs explaining them in detail, so here is a blog article I found on Google explaining how they are useful.
Update: you can find a precise definition of existential types in the Scala specification but it is quite dense.
code :
def printFirst(x : Array[T] forSome {type T}) = println(x(0)) 
def printFirst[T](x : Array[T]) = println(x(0))
def addToFirst(x : Array[T] forSome {type T <: Integer}) = x(0) + 1
Scala parameter type explanation

Scala parameter type explanation


By : THEPADA
Date : March 29 2020, 07:55 AM
it helps some times In general, => A is a by name parameter of type A. That means the parameter will only be evaluated if and when (and each time) it is used in the body of the function. Thus, f is a by name parameter whose type is a function that takes a String and returns a function from a Request[AnyContent] to a Result. Here is an example of how by name parameter are evaluated:
code :
scala> def twice[A](a: =>A) = (a,a)
twice: [A](a: => A)(A, A)

scala> var i = 0
i: Int = 0

scala> twice {
     |   i += 1
     |   i
     | }
res0: (Int, Int) = (1,2)
What is and when to use Scala's forSome keyword?

What is and when to use Scala's forSome keyword?


By : mayowa temitope
Date : March 29 2020, 07:55 AM
this one helps. Attention: (Update 2016-12-08) The forSome keyword is very likely going away with Scala 2.13 or 2.14, according to Martin Odersky's talk on the ScalaX 2016. Replace it with path dependent types or with anonymous type attributes (A[_]). This is possible in most cases. If you have an edge case where it is not possible, refactor your code or loosen your type restrictions.
How to read "forSome" (in an informal way)
Type selection, type projection. What is S#T in Scala ? Scala Language Specification based explanation is needed

Type selection, type projection. What is S#T in Scala ? Scala Language Specification based explanation is needed


By : sashka
Date : March 29 2020, 07:55 AM
may help you . I don't have a legalistic understanding of A#B (only a practical one) so I can't help with the first part, but I can answer your final question: per 3.2.3, the type o1.Inner is o1.type#Inner. Per 3.5.2, "A type projection T#t conforms to U#t if T conforms to U". Hopefully it's obvious that o1.type <: Outer; strictly this is because (again in 3.5.2) "A singleton type p.type conforms to the type of the path p".
Scala method type parameter can not accept existential type in forSome form

Scala method type parameter can not accept existential type in forSome form


By : Đoàn Lại Giang
Date : March 29 2020, 07:55 AM
it should still fix some issue The confusion is that the underscore (_) in foo does not denote an existential type.
Let's see what the following actually means:
code :
def foo[List[_]](x: List[_]) = x
def foo[List[_]](x: List[T] forSome { type T }) = x
def foo(x: List[T] forSome { type T }) = x
def foo(x: List[_]) = x
Related Posts Related Posts :
  • macro does not find out enclosing vals
  • Spark : how to run spark file from spark shell
  • Flattening a list of lists to a set with exceptions in scala
  • flatMap implementation in Scala
  • Confused about a few lines code in a scala official document page
  • How to input parameters when running bash command with Scala
  • Location header is lost if max-redirects > 1
  • Controller Spec is using FakeApplication, but can't load test configuration
  • Scala code analyzer targets case variable names that are identical to the outer matched varables - "suspicous shado
  • Why does authorize directive execute after the code it's supposed to protect?
  • Scala. Checking if a Type is Comparable
  • Does having a private constructor on a value class negate the benefits of a value class?
  • How to transform submitted json in Play 2.0?
  • Scala warning match may not be exhaustive
  • Pure not a member of objective Promise in PlayFramework
  • How to unmarshal POST params and JSON body in a single route?
  • Spark:How to use join method?
  • is client thread-safe in Twitter Finagle
  • Why is the method accepts only one argument?
  • Scala Play 2.3 Working with gCloud Storage - any libs to go async?
  • spray.io strange get/delete/detach directives behavior
  • SBT cannot resolve class declared in src/main/scala in a src/test/scala test class
  • Scala typeclass without function argument
  • Configuring actor behavior using typesafe Config and HOCON
  • Scalatra: Migrating Jersey Filters to Scalatra
  • Compilation error when using Scaldi
  • Scalac hanging in phase typer
  • how to have different source code when cross-compiling Scala with sbt? (changes in MurmurHash)
  • How to set different scalacOptions per Scala version when cross-compiling using Build.scala?
  • Possible Bug in JDBC?
  • Is there a Scala compiler flag to warn when tail recursion is applied without annotation?
  • scala case class put methods in companion object?
  • multiproject sbt doesn't generate file structure
  • Scala "multilevel" abstract class / abstract objects replacement
  • Scala, getting the type parameters of a KList as an HList
  • Why does Play refuse form reporting "Cannot resolve method apply with such signature: Missing arguments"?
  • How to split string with trailing empty strings in result?
  • Scala group by list of list and subtracts grouped values
  • Scala - Creating a function to produce Unary string or integer values
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org