Joyless narrow type loss

In the following example

import shapeless._
import shapeless.syntax.singleton._

val concat = "right".narrow

def extract[s <: String](x: s)(implicit witness: Witness.Aux[s]): String = witness.value

extract(concat)

I get an error

Error: could not find implicit parameter value witness:shapeless.Witness.Aux[String("right")]

What I'm trying to do is a type-level DSL that relied heavily on singleton types.

Since single typed literals are poorly supported outside the level plug, I was hoping to develop cost-based DSLs in addition to type literals, and keeping the same types used in value types is crucial for this task. So I'm looking for any workaround that allows me to extract the syntax string witness from the value type later.

Edit

Operations

using .witnessinstead .narrowworks fine, but I'm still looking for a solution for pure types without Witnesswrapping

+4
1

... ,

extract[concat.type](concat)

, .

, , , value extract. shapeless Witness, :

def extract(witness: Witness.Lt[String]): String = witness.value

Strings, .

+5

Source: https://habr.com/ru/post/1661824/


All Articles