- About Scala
- In the Enterprise
- Scala Community
- Language Research
- In the Press
- The Scala Team
- Scala's Prehistory
- Contact Us
- Learning Scala
- Tour of Scala
- Scala API
- Setup & Getting Started
- Programming Guides
- Other Guides
- Code Examples
- Scala Developers
Could quasiquotes do this?
One thing that I'm finding myself wanting quite frequently these days
is a way of having the compiler verify for me that something otherwise
well-formed doesn't in fact typecheck. The test suite and examples for
shapeless are littered with commented out lines like,
def acceptOption[L <: HList : TC[Option]#λ](l : L) = true
val l1 = Option(23) :: Option(true) :: Option("foo") :: HNil
val l2 = Option(23) :: true :: Option("foo") :: HNil
acceptOption(l1) // Compiles
//acceptOption(l2) // Does not compile
which is pretty useless if I should ever break things in such a way
that the last line actually _did_ compile.
Is there something that quasiquotation could do for us here? Would it
be possible to support something like,
which typechecks iff acceptOption(l2) is a type error (but not if, eg.
l2 is undefined)?