« 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 Florian Hars-3 :: Rate this Message:

Reply to Author | View in Thread

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

The type you specified is

  exists K . (Int, Map[K, Int]) => Map[K, Int]

but the type you are after is

  forall K . (Int, Map[K, Int]) => Map[K, Int]

That is universal, not existential. And universal types are the prototypical
hypothetical improvement to scala
(see http://lampsvn.epfl.ch/svn-repos/scala/sip/trunk/sips/sip-00000.xhtml).

This may be related, too:
http://existentialtype.net/2008/05/26/revisiting-higher-rank-impredicative-polymorphism-in-scala/
but it looks too scary for me right now.
IIRC i've read somewhere else that you can get the effect you want by
CPS-transforming your program, but I am not sure that this would be an
improvement in the scariness department.

- Florian

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

LightInTheBox - Buy quality products at wholesale price!