I have the following code:
import shapeless._
trait TypeLike
case class Arg(name:String)
case class Predicate[Args <: HList, O <: TypeLike](name: String,args:Args,output:O,func: Args => O)(implicit val lubWitness: LUBConstraint[Args, Arg])
(It was result of a question from: Here) And I want to have:
import scalax.collection.edge.LDiEdge
import scalax.collection.immutable.Graph
import scalax.collection.edge.Implicits._
import shapeless._
case class SimplePlan[A<:HList,B<:TypeLike,N<:Predicate[A,B]](plan:Graph[N,LDiEdge])
I get type mismatch and inferred type argument error on following code:
object testMe extends App{
val p1 = Predicate("Example1", Arg("test")::Arg("test")::HNil, new TypeLike {},
(args: Arg ::Arg:: HNil) => { println(args(0));new TypeLike {} })
val p2 = Predicate("Example2", Arg("test")::HNil, new TypeLike {},
(args: Arg :: HNil) => { println(args(0));new TypeLike {} })
val x = Graph((p1 ~+> p2)("booo"))
val p = SimplePlan(x)
}
What exactly I have to add to solve the problem? In case you want to have the dependencies:
scalaVersion := "2.10.4"
libraryDependencies += "com.assembla.scala-incubator" %% "graph-core" % "1.9.1"
libraryDependencies += "com.chuusai" % "shapeless_2.10.4" % "2.1.0"
Edit: (more explanation)
Predicate class is a class with a function "func" that can get variable number of arguments. I implemented this using the question I asked earlier (the link is there) I can instantiate from the Predicate now, p1 and p2. I have another class "SimplePlan" which has a member of a graph that I want its nodes to be a Predicate. But because I'm using HList in Predicate definition, type of each p1 and p2 are different. I get type mismatch error on:
val p = SimplePlan(x)
I really don't know, how should I define SimplePlan to resolve this problem. The exact error is:
Error: inferred type arguments [Nothing,Nothing,Planner.Predicate[_ >: shapeless.::[Planner.Arg,shapeless.HNil] with shapeless.::[Planner.Arg,shapeless.::[Planner.Arg,shapeless.HNil]] <: shapeless.::[Planner.Arg,shapeless.HList], Planner.TypeLike]] do not conform to method apply's type parameter bounds [A <: shapeless.HList,B <: Planner.TypeLike,N <: Planner.Predicate[A,B]]
val p = SimplePlan(x)
^
Error: type mismatch;
found : scalax.collection.immutable.Graph[Planner.Predicate[_ >: shapeless.::[Planner.Arg,shapeless.HNil] with shapeless.::[Planner.Arg,shapeless.::[Planner.Arg,shapeless.HNil]] <: shapeless.::[Planner.Arg,shapeless.HList], Planner.TypeLike],scalax.collection.edge.LDiEdge]
required: scalax.collection.immutable.Graph[N,scalax.collection.edge.LDiEdge]
val p = SimplePlan(x)
^
Edit 2 (Explanation of what exactly I want): I need this for my research project, so what I want to do could be a little bit weird. I want to have a predicate class that has a function in it with different number and type parameters. I want to have a graph (which is my execution graph). I can get rid of HList for parameters but I will loose type information!
Arg :: HNil
andArg :: Arg :: HNil
, which isn't anything meaningful. WhatA
do you expect to be inferred forSimplePlan
? – Travis BrownArg:: HNil
and 'Arg::Arg::HNil` both<: HList
? I want to have a type forSimplePlan
that allows any kind ofPredicate
? I even don't know if it's possible when I have an HList in my class members – OmidHList
s, but there's pretty much nothing you can do with a plainHList
. – Travis Brown