These are chat archives for typelevel/scala

8th
Sep 2017
Ruslan Feizerahmanov
@Russoul
Sep 08 2017 17:40

Still trying to get a grasp of typelevel nat ops (from shapeless), can really appreciate some help )

I have the following (hope working) implementation of size encoded list:

sealed trait SVec[+A,Q <: Nat]{
   def ::[B >: A, N <: Nat](x : B)(implicit sum: Sum.Aux[Q,Nat._1,N]) = new ::[B,Q,N](x,this)
}
object SNil extends SVec[Nothing, _0]
class ::[+A,Q <: Nat,N <: Nat](val x : A, val xs : SVec[A, Q]) extends SVec[A,N]
object ::{
   def unapply[A,Q <: Nat, N <: Nat](obj : ::[A,Q,N]) = Some(obj.x, obj.xs)
}

How to implement, say, replicate operation:

def replicate[T, N <: Nat](e:T)(...) : SVec[T,N] = ???