Created
September 12, 2013 05:54
-
-
Save jonifreeman/6533463 to your computer and use it in GitHub Desktop.
Explicit type for a Shapeless record.
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 TestExplicitRecordType { | |
import shapeless._, record._, syntax.singleton._ | |
object testF extends Poly1 { | |
implicit def atFieldType[F, V](implicit wk: shapeless.Witness.Aux[F]) = at[FieldType[F, V]] { | |
f => wk.value.toString | |
} | |
} | |
// Is there more straighforward way to give an explicit type for a record? | |
val k1 = Witness("k1") | |
val k2 = Witness("k2") | |
type Error = FieldType[k1.T, String] :: FieldType[k2.T, Long] :: HNil | |
// That seems to work... | |
val err1 = "k1" ->> "1" :: "k2" ->> 1L :: HNil | |
val err2: Error = "k1" ->> "1" :: "k2" ->> 1L :: HNil | |
// ... except. Looks like evidence for Witness.Aux is lost. | |
testF(err1.head) // OK | |
testF(err2.head) // could not find implicit value for parameter cse: shapeless.poly.Case[testF.type,shapeless.::[shapeless.record.FieldType[k1.T,String],shapeless.HNil]] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this is now addressed via the new record type literals in shapeless 2.1.0 ... does this resolve the problem for you?