singleton-type

Is there anyway, in Scala, to get the Singleton type of something from the more general type?

亡梦爱人 提交于 2021-02-04 08:35:24
问题 I have a situation where I'm trying to use implicit resolution on a singleton type. This works perfectly fine if I know that singleton type at compile time: object Main { type SS = String with Singleton trait Entry[S <: SS] { type out val value: out } implicit val e1 = new Entry["S"] { type out = Int val value = 3 } implicit val e2 = new Entry["T"] { type out = String val value = "ABC" } def resolve[X <: SS](s: X)(implicit x: Entry[X]): x.value.type = { x.value } def main(args: Array[String])

replicate function for a length-indexed list using GHC.TypeLits and singletons

不打扰是莪最后的温柔 提交于 2020-01-11 07:34:08
问题 I'm trying to write a replicate function for a length-indexed list using the machinery from GHC.TypeLits, singletons, and constraints. The Vect type and signature for replicateVec are given below: data Vect :: Nat -> Type -> Type where VNil :: Vect 0 a VCons :: a -> Vect (n - 1) a -> Vect n a replicateVec :: forall n a. SNat n -> a -> Vect n a How can you write this replicateVec function? I have a version of replicateVec that compiles and type checks, but it appears to go into an infinite

replicate function for a length-indexed list using GHC.TypeLits and singletons

一个人想着一个人 提交于 2020-01-11 07:34:07
问题 I'm trying to write a replicate function for a length-indexed list using the machinery from GHC.TypeLits, singletons, and constraints. The Vect type and signature for replicateVec are given below: data Vect :: Nat -> Type -> Type where VNil :: Vect 0 a VCons :: a -> Vect (n - 1) a -> Vect n a replicateVec :: forall n a. SNat n -> a -> Vect n a How can you write this replicateVec function? I have a version of replicateVec that compiles and type checks, but it appears to go into an infinite