Last active
December 24, 2015 02:59
-
-
Save Danny02/6734531 to your computer and use it in GitHub Desktop.
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
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