SHARE
TWEET

Untitled

a guest Feb 24th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. scala> trait A
  2. defined trait A
  3. scala> class B extends A
  4. defined class B
  5. scala> class C extends A
  6. defined class C
  7. scala> Some(0).fold(new B){_=>new C}
  8. <console>:11: error: type mismatch;
  9.  found   : C
  10.  required: B
  11.               Some(0).fold(new B){_=>new C}
  12.    
  13. scala> def meth[A](a1: A, a2: A) = (a1, a2)
  14. meth: [A](a1: A, a2: A)(A, A)
  15.  
  16. scala> meth(1, "")
  17. res7: (Any, Any) = (1,"")
  18.  
  19. scala> def meth[A](a1: A)(a2: A) = (a1, a2)
  20. meth: [A](a1: A)(a2: A)(A, A)
  21.  
  22. scala> meth(1)("")
  23. <console>:10: error: type mismatch;
  24.  found   : String("")
  25.  required: Int
  26.               meth(1)("")
  27.                       ^
  28.    
  29. scala> List(1).foldLeft(Nil)((xs,x) => x::xs)
  30. <console>:8: error: type mismatch;
  31.  found   : List[Int]
  32.  required: scala.collection.immutable.Nil.type
  33.               List(1).foldLeft(Nil)((xs,x) => x::xs)
  34.                                                ^
  35.    
  36. scala> List(1).foldLeft(Nil)((xs,x) => x::xs)
  37. <console>:8: error: type mismatch;
  38.  found   : List[Int]
  39.  required: scala.collection.immutable.Nil.type
  40.               List(1).foldLeft(Nil)((xs,x) => x::xs)
  41.                                                ^
  42.  
  43. scala> List(1).foldLeft(Nil : List[Int])((xs,x) => x::xs)
  44. res1: List[Int] = List(1)
  45.    
  46. Some(0).fold(new B : A){_=>new C}
  47.    
  48. Some(0).fold(new B: A){_=>new C}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top