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

Scala example source code file (depmet_implicit_norm_ret.scala)

This example Scala source code file (depmet_implicit_norm_ret.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

a, anyref, s, s, stream, stream, succzipwith, t, t, test, zerozipwith, zipwith, zipwith, zipwithdefault

The Scala depmet_implicit_norm_ret.scala source code

object Test{
  def ?[S <: AnyRef](implicit w : S) : w.type = w
  
  // fallback, lower priority (overloading rules apply: pick alternative in subclass lowest in subtyping lattice)
  class ZipWithDefault {
    implicit def ZeroZipWith[S] = new ZipWith[S] {
      type T = Stream[S]
    }    
  }
  
  object ZipWith extends ZipWithDefault {
    // def apply[S: ZipWith](s : S) = ?[ZipWith[S]].zipWith(s) // TODO: bug return type should be inferred
    def apply[S](s : S)(implicit zw: ZipWith[S]): zw.T = zw.zipWith(s)

    implicit def SuccZipWith[S,R](implicit zWith : ZipWith[R]) = new ZipWith[S => R] {
      type T = Stream[S] => zWith.T // dependent types replace the associated types functionality
    }    
  }
  
  trait ZipWith[S] {
    type T
    def zipWith : S => T = error("")
  }
  
  // bug: inferred return type = (Stream[A]) => java.lang.Object with Test.ZipWith[B]{type T = Stream[B]}#T
  // this seems incompatible with vvvvvvvvvvvvvvvvvvvvvv   -- #3731
  def map[A,B](f : A => B)   /* : Stream[A] => Stream[B]*/ = ZipWith(f) 
  val tst: Stream[Int] = map{x: String => x.length}(Stream("a"))  
}  

Other Scala examples (source code examples)

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

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

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 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.