Skip to content

Instantly share code, notes, and snippets.

@Danny02
Last active December 24, 2015 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Danny02/6734531 to your computer and use it in GitHub Desktop.
Save Danny02/6734531 to your computer and use it in GitHub Desktop.
import shapeless._
object Bullshit {
sealed abstract class Size[T](val size:Int)
object Size{
implicit object sizeForString extends Size[String](9)
implicit object sizeForInt extends Size[Int](4)
implicit object sizeForFloat extends Size[Float](7)
}
type stuff = String :: Int :: Float :: HNil
def size[T <: HList](implicit s : ToSize[T]) = s()
//doesn't compile
val c = size[stuff]
val d = implicitly[ToSize[stuff]]
trait ToSize[-L <: HList] {
def apply() : Int
}
object ToSize {
implicit val toSize0 = new ToSize[HNil] {
def apply() = 0
}
implicit def toSizeSucc[T, L <: HList](implicit toSizeN : ToSize[L], s : Size[T]) = new ToSize[T :: L] {
def apply() = toSizeN() + s.size
}
}
//compiles
//val c = size[stuff]
//val d = implicitly[ToSize[stuff]]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment