I am trying to translate the code in the (very interesting) paper Build systems a la carte from Haskell to Scala, for self-study. I am far from being an expert in Scala or Haskell, so I got stuck when trying to write an equivalent of (page 7):
newtype Task c k v = Task { run :: forall f. c f => (k -> f v) -> f v }
type Tasks c k v = k -> Maybe (Task c k v)
After reading the post forall in Scala, I made a tentative to translate the type constraint specified by the forall:
import scalaz.Applicative
import scala.language.higherKinds
trait MyApplicative[_] {}
trait SuchThat[F[_], G[_]] {
def apply[A:G]: F[A]
}
trait Task[C[_], K, V] {
type F[X] = ({type f[_]})#f SuchThat C
var runInt: (K => F[V]) => F[V] = null
def run = {runInt}
def apply(r: (K => F[V]) => F[V] ) = {
runInt = r
}
}
class ApplicativeTask[K, V] extends Task[Applicative, K, V] {}
class MyTask[K,V] extends Task[MyApplicative, K, V] {}
object TasksObj {
type Tasks[C[_], K, V] = K => Option[Task[C, K, V]]
}
but I got this error message:
Error: kinds of the type arguments (scalaz.Applicative,K,V) do not conform to the expected kinds of the type parameters (type C,type K,type V) in trait Task.
scalaz.Applicative's type parameters do not match type C's expected parameters:
type F has one type parameter, but type _ has none
class ApplicativeTask[K, V] extends Task[Applicative, K, V] {
I got no errors for class MyTask, instead. I suppose it's because Scalaz Applicative takes a type constructor as parameter (as far as I understand), and MyApplicative a simple type.
I lost myself in the intricacies of Scala type system, so I would appreciate if someone could help me find a solution.
Thanks in advance.