shapeless

How to create an instances for typeclass with dependent type using shapeless

旧城冷巷雨未停 提交于 2020-11-29 09:32:58
问题 I'm trying to derive a tuple instance for a type class with dependent type. I'm using shapeless to create summon the type class for the tuple elements. I'm having trouble matching tuple instance types: import shapeless.the import simulacrum.typeclass @typeclass trait Identifiable[M] { type K def identify(id: M): K } object Identifiable{ implicit def identifiableTuple[K1: Identifiable, K2: Identifiable]: Identifiable[(K1,K2)] = new Identifiable[(K1,K2)]{ val b = the[Identifiable[K2]] val a =

Get type of a “singleton type”

橙三吉。 提交于 2020-08-22 05:21:30
问题 We can create a literal types via shapeless: import shapeless.syntax.singleton._ var x = 42.narrow // x: Int(42) = 42 But how can I operate with Int(42) as a type if it's even impossible to create type alias type Answ = Int(42) // won't compile // or def doSmth(value: Int(42)) = ... // won't compile 回答1: 1) In Typelevel Scala you can write just val x: 42 = 42 type Answ = 42 def doSmth(value: 42) = ??? 2) In Dotty Scala you can write the same. 3) In Lightbend Scala (i.e. standard Scala) +

In scala, are there any condition where implicit view won't be able to propagate to other implicit function?

核能气质少年 提交于 2020-08-20 10:35:27
问题 Assuming that A class called 'summoner' was defined, that is capable of summoning implicit views from the scope: case class Summoner[R]() { def summon[T](v: T)(implicit ev: T => R): R = ev(v) } I found that it works most of the time, but there are cases where it doesn't work, e.g. the following is a (not too) short case which uses the singleton-ops library: import shapeless.Witness import singleton.ops.+ import singleton.ops.impl.Op trait Operand { def +[ X >: this.type <: Operand, Y <: