Created
February 5, 2014 10:32
-
-
Save possiblywrong/8820864 to your computer and use it in GitHub Desktop.
Shapeless poly binding & inference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object TestCase { | |
// Given input of type X return a function of | |
// type List[(A,B)] => List[B] forall B | |
// Types X & A are related | |
object filt extends Poly1 { | |
implicit def caseOne = at[Int]( i => { | |
object partialbind extends somefn(i); | |
partialbind | |
} ) | |
// ...may have other cases | |
} | |
class somefn(j: Int) extends Poly1 { | |
implicit def caseOne[A] = at[List[(Int,A)]]( xs => xs.filter(_._1 == j).map(_._2) ) | |
} | |
val t1 = filt(4) | |
val t2 = filt(5)(List((1,1),(5,5))) | |
// type mismatch; | |
// [error] found : List[(Int, Int)] | |
// [error] required: shapeless.poly.Case[discsort.TestCase.filt.type,shapeless.::[Int,shapeless.HNil]] | |
// [error] val t2 = filt(5)(List((1,1),(5,5))) | |
// [error] ^ | |
} | |
object TestCase2 { | |
// Given input of type X return a function of | |
// type List[(A,B)] => List[B] forall B | |
// Types X & A are related | |
object filt extends Poly1 { | |
implicit def caseOne[A] = at[Int]( i => { | |
xs: List[(Int,A)] => xs.filter(_._1 == i).map(_._2) | |
} ) | |
// ...may have other cases | |
} | |
val t1 = filt[String](4) | |
// overloaded method value apply with alternatives: | |
// [error] (implicit c: discsort.TestCase2.filt.ProductCase.Aux[shapeless.HNil,String])String <and> | |
// [error] (a: String)(implicit cse: shapeless.poly.Case[discsort.TestCase2.filt.type,shapeless.::[String,shapeless.HNil]])cse.Result | |
// [error] cannot be applied to (Int) | |
// [error] val t1 = filt[String](4) | |
// [error] ^ | |
val t2 = filt[Int](5)(List((1,1),(5,5))) | |
// type mismatch; | |
// [error] found : List[(Int, Int)] | |
// [error] required: shapeless.poly.Case[discsort.TestCase2.filt.type,shapeless.::[Int,shapeless.HNil]] | |
// [error] val t2 = filt[Int](5)(List((1,1),(5,5))) | |
// [error] ^ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The only currification I could find with Poly2 is the following stupid one :)