scala - What is type declartion for in definition of Nat in shapeless? -
this definition of nat in package shapeless:
   trait nat {      type n <: nat    }     case class succ[p <: nat]() extends nat {      type n = succ[p]    }     class _0 extends nat serializable {      type n = _0    } what type declarations ?  once removed seems me definition works equally well.
they're used nat target type of implicit conversion literal int ... see here, example, in definition of int indexing method hlist,
def at(n : nat)(implicit @ : at[l, n.n]) : at.out = ... here intention method invoked literal int argument,
(23 :: "foo" :: true :: hnil).at(1) the argument converted nat implicit macro able inspect compile time argument tree , construct corresponding nat value. can refer type member n of n , use index at type class extracts desired element hlist.
Comments
Post a Comment