Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to "curry" higher-kinded types in Scala?

Let's suppose I have a trait with two type parameters, e.g.

trait Qux[A, B]

and another trait with a higher-kinded type parameter, e.g.

trait Turkle[C[_]]

I'd like to be able to substitute a fixed value for one of the type parameters for Qux, so that it can be used to parametrize Turkle.

Here's an example (of code that doesn't make sense in Scala!):

trait Baz[A] extends Turkle[Qux[A, _]]

Anyone have any ideas how to achieve this effect?

like image 1000
Scott Morrison Avatar asked Jun 06 '11 04:06

Scott Morrison


2 Answers

Jason Zaugg came up with the most succinct way to do this:

trait Baz[A] extends Turkle[({type x[a]=Qux[A, a]})#x]

IntelliJ's Scala plugin will optionally collapse this to:

trait Baz[A] extends Turkle[x[a]=Qux[A, a]]
like image 160
Lachlan Avatar answered Nov 06 '22 00:11

Lachlan


You mean something like this?

trait QuxWithString[A] extends Qux[A, String]
new Turkle[QuxWithString]{}

This is the analog to partial application for types.

like image 4
Kim Stebel Avatar answered Nov 06 '22 02:11

Kim Stebel