alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (t4692.scala)

This example Scala source code file (t4692.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

error, for, for, mylist, mylist, mylistofint, mylistofint, typealiasvsimplicittest, typealiasvsimplicittest

The Scala t4692.scala source code

class TypeAliasVsImplicitTest {

    class For[m[_], a](x: m[a]) {
       def map[b](y: a => b): m[b] = throw new Error
    }
    implicit def toFor[m[_], a](x: m[a]): For[m, a] = new For[m, a](x)

    trait MyList[A]

    def foo(xs: MyList[Int]) = xs.map(x => x) // compiles fine.

    type MyListOfInt = MyList[Int]
    def bar(xs: MyListOfInt) = xs.map(x => x) // doesn't compile: value map is not a member of TypeAliasVsImplicitTest.this.MyListOfInt
}

// minimal case -- the bug was in type constructor inference where `xs.type` needed to be widened *and* dealiased
// in 2.8.1 implicit conversion search started with a widened type, so that combo never came up
// object Test {
//   class For[m[_], a](x: m[a])
//   def toFor[m[_], a](x: m[a]): For[m, a] = new For[m, a](x)
//
//   trait MyList[A]
//   type MyListOfInt = MyList[Int]
//
//   val xs: MyListOfInt = error("")
//   toFor(xs : xs.type)
// }

Other Scala examples (source code examples)

Here is a short list of links related to this Scala t4692.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.