« Return to Thread: [scala] Using existential types to get rid of extraneous type parameters

Re: [scala] Using existential types to get rid of extraneous type parameters

by Alex Boisvert-3 :: Rate this Message:

Reply to Author | View in Thread

On Thu, Jul 17, 2008 at 11:36 AM, Paul Chiusano <paul.chiusano@...> wrote:
Take the following function:

  def integerDivide[K](denominator: Int, vs: Map[K,Int]): Map[K,Int] =
    vs.transform((k,v) => v/denominator)

It seems silly to have K appear as a type parameter to this function since it is not "touched" by the body of the function.

I don't think it's silly because it specifies that the return type is the same as the type passed in.  Otherwise, you're looking at an undefined return type....

alex

 « Return to Thread: [scala] Using existential types to get rid of extraneous type parameters

LightInTheBox - Buy quality products at wholesale price!