by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 06 15:26
    Travis milessabin/shapeless (shapeless-3) passed (3052)
  • Jun 06 15:26
    Travis milessabin/shapeless (shapeless-3-staging) passed (3053)
  • Jun 06 15:24

    milessabin on shapeless-3-staging

    Bumped Dotty and Scala versions Merge pull request #1017 from m… Drop Scala 2 from x-build to pr… and 5 more (compare)

  • Jun 06 15:22

    milessabin on shapeless-3

    ensure bounds and aliases are f… Bumped Dotty and SBT versions Macro errors now via Reporting and 1 more (compare)

  • Jun 06 15:22
    milessabin closed #1026
  • Jun 06 15:22
    milessabin commented #1026
  • Jun 06 14:12
  • Jun 06 14:10
    Travis milessabin/shapeless (topic/dotty-updates) passed (3050)
  • Jun 06 14:09
    milessabin opened #1026
  • Jun 06 14:08

    milessabin on dotty-updates

    Merge pull request #1017 from m… Drop Scala 2 from x-build to pr… Merge pull request #1018 from m… and 3 more (compare)

  • May 31 11:14
    Travis milessabin/shapeless (master) passed (3049)
  • May 31 10:42

    milessabin on master

    Update sbt to 1.3.12 Merge pull request #1025 from s… (compare)

  • May 31 10:42
    milessabin closed #1025
  • May 31 10:41
    milessabin review_requested #1025
  • May 31 02:18
  • May 31 02:02
    scala-steward opened #1025
  • May 30 11:30
    Travis milessabin/shapeless (master) passed (3047)
  • May 30 10:57

    milessabin on master

    Update sbt to 1.3.11 Merge pull request #1024 from s… (compare)

  • May 30 10:57
    milessabin closed #1024
  • May 30 10:56
    milessabin review_requested #1024
Dmytro Mitin
@DmytroMitin
@elyphas Notice that itemLst is just an HList so LabelledGeneric[Item].from(itemLst) won't work.
elyphas
@elyphas
@DmytroMitin , oh yes, sorry; https://scalafiddle.io/sf/MKt06MV/1
I didn't update the fiddle, I am very sorry.
this works
Dmytro Mitin
@DmytroMitin
@elyphas again LabelledGeneric[Item].from(itemLst) doesn't compile
elyphas
@elyphas
ah, I know what you mean, back to case class
ah ok, I get it.
I was looking for avoid the type class, :)
@DmytroMitin ; thank you!,
elyphas
@elyphas
@DmytroMitin , the algorithm explained in the chapter 5.3 of The Type Astronaut’s Guide to Shapeless, is what I need but instead of JsonObject I need to return FieldType.
am I right?
Dmytro Mitin
@DmytroMitin

@elyphas well, you better know what you're doing. I just meant that pattern matching at runtime

 def foo(l: HList) = l match {
    case h :: t => ???
    case HNil => ???
  }

is similar to type classes at compile time

  trait Foo[L <: HList]
  object Foo {
    implicit def hcons[H, T <: HList]: Foo[H :: T] = ???
    implicit def hnil: Foo[HNil] = ???
  }
elyphas
@elyphas
@DmytroMitin , ah thank you.
elyphas
@elyphas

Hi, someone could tell me, please, what is wrong with code:

implicit def hListFieldsSelector[U, Value, Key, TargetHListTail <: HList, SourceHList <: HList](
                implicit restFieldsSelect: FieldsSelector[SourceHList, TargetHListTail],
                key: Witness.Aux[ Symbol @@ U ],
                select: Selector.Aux[SourceHList, Key, Value]     // select the value of type Value labelled with Key from a HList of type Source
            ): FieldsSelector[SourceHList, FieldType[Symbol @@ U, Value] :: TargetHListTail] =
                new FieldsSelector[SourceHList, FieldType[Symbol @@ U, Value] :: TargetHListTail] {
                        def apply(source: SourceHList):
                                FieldType[Symbol @@ U, Value] :: TargetHListTail = {
                                    val fld = key.value.name
                                    val valor = select(source)
                                    val ver = ( fld ->> valor ) ::  ( key.value ->> valor ) :: HNil
                                    //field[Key](select(source)) :: restFieldsSelect(source)
                                    (fld ->> valor)
                                }
                }

I am trying to adapt it to return a Record

elyphas
@elyphas
I have this error:
FieldSelector.scala:32:46: type mismatch;
[error]  found   : select.Out
[error]     (which expands to)  Value
[error]  required: shapeless.labelled.FieldType[Symbol @@ U,Value] :: TargetHListTail
[error]     (which expands to)  Value with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[U],Value] :: TargetHListTail
[error]                                     (fld ->> valor)
Ethan
@esuntag
Where does FieldsSelector come from?
Ethan
@esuntag
Anyway, this seems to compile:
implicit def hListFieldsSelector[U, Value, Key, TargetHListTail <: HList, SourceHList <: HList](
  implicit
  restFieldsSelect: FieldsSelector[SourceHList, TargetHListTail],
  key: Witness.Aux[ Symbol @@ U ],
  select: ops.record.Selector.Aux[SourceHList, Key, Value]     // select the value of type Value labelled with Key from a HList of type Source
): FieldsSelector[SourceHList, select.Out :: TargetHListTail] =
  new FieldsSelector[SourceHList, select.Out :: TargetHListTail] {
    def apply(source: SourceHList):
      FieldType[Key, Value] :: TargetHListTail = {
        val fld = key.value.name
        val valor = select(source)
        field[Key](select(source)) :: restFieldsSelect(source)
      }
  }
elyphas
@elyphas
@esuntag , thank you.
elyphas
@elyphas

sorry, me again, I am stuck now with a loose implicit.
I have this error:

could not find implicit value for parameter fldLister: simpleDerivation2.FieldLister2[Main.Ver]
[error]   val ve = FieldLister2[Ver]
[error]                        ^

but I think this must do the work:

implicit def genericLister[A, R](implicit
                                   gen: LabelledGeneric.Aux[A, R],
                                   lister: Lazy[FieldLister2[R]] ): FieldLister2[A] =
    new FieldLister2[A] {
      override val list = lister.value.list
    }

someone could take a look at my code, please, :)
https://scalafiddle.io/sf/MKt06MV/4

Dmytro Mitin
@DmytroMitin

@elyphas Do you know how to debug implicits in Scala? https://stackoverflow.com/a/59349514/5249621
Try to resolve them manually. You'll see compile error.

  FieldLister2[Ver](FieldLister2.genericLister[Ver, Record.`'a -> String, 'b -> Int`.T](
   implicitly[LabelledGeneric.Aux[Ver, Record.`'a -> String, 'b -> Int`.T]],
    Lazy(FieldLister2.hconsLister[Witness.`'a`.T, String, Record.`'b -> Int`.T](
      Lazy(???),
      implicitly[Selector.Aux[Record.`'b -> Int`.T, Witness.`'b`.T, Int]],
      FieldLister2.hconsLister[Witness.`'b`.T, Int, HNil](
        Lazy(???),
        ???,
        FieldLister2.hnilLister
      )
    ))
  ))

Fill ???s. If you can't resolve implicits manually compiler will not be able either.

elyphas
@elyphas
@DmytroMitin ; no, I didn't know it was possible to debug implicits
thank you
Dmytro Mitin
@DmytroMitin
@elyphas In Type astronaut there is chapter about this "3.5 Debugging implicit resolution" https://books.underscore.io/shapeless-guide/shapeless-guide.html#sec:generic:debugging
elyphas
@elyphas
@DmytroMitin ; oh yes, I forgot, too many information, :)
thank you
I was focusing in the part "5.3", how to make the recursion.
Andrey Ivanov
@a_nigredo_twitter

Hi all, I have a code for getting string from string pool an compile-time:

    final case class Foo(int: Int, long: Long)

    trait Name {
      type R <: String
      val name: R

      override def toString: String = name
    }

    trait NameR[S <: String] extends Name {
      type R = S
      val name: S
    }

    object Name {
      def apply(name0: String): NameR[name0.type] = new NameR[name0.type] {
        override type R = name0.type
        override val name: name0.type = name0
      }
    }

    class Holder[H <: HList](hlist: H) {

      def add(name: String): Holder[NameR[name.type] :: H] = new Holder[NameR[name.type] :: H](Name(name) :: hlist)

      def select(name: String)(implicit selector: NameSelector[H, name.type]): String = name
    }

    object Holder extends Holder(HNil: HNil)

    @implicitNotFound("Could not find field ${S} in ${L}")
    trait NameSelector[L <: HList, S <: String] {
      def apply(l: L): NameR[S]
    }

    object NameSelector {

      def apply[L <: HList](name: String, l: L)(implicit selector: NameSelector[L, name.type]): NameR[name.type] =
        selector.apply(l)

      def apply[L <: HList, S <: String](implicit selector: NameSelector[L, S]): NameSelector[L, S] = selector

      implicit def select[S <: String, T <: HList]: NameSelector[NameR[S] :: T, S] =
        (l: NameR[S] :: T) => l.head

      implicit def recurse[S1 <: String, S <: String, T <: HList](implicit st: NameSelector[T, S]): NameSelector[NameR[S1] :: T, S] =
        (l: NameR[S1] :: T) => st.apply(l.tail)
    }

I can use it like:

    val fields = Holder.add("int").add("long")
    fields.select("int")

Now I want to implement the same thing above but for case class fields which should automatically added into my string pool. Smth like this:

 val lbl = LabelledGeneric[Foo]
 val keys = Keys[lbl.Repr].apply

 val fields = keys.foldLeft(Holder)(???)
  fields.select("int")

but I don't know how to implement poly fold function
Can somebody help me?

Dmytro Mitin
@DmytroMitin
@a_nigredo_twitter First of all, hlist keys contains Symbols, not Strings.
Andrey Ivanov
@a_nigredo_twitter
yeap, but Holder can use string. It s just a wrapper for hlist with string support
Dmytro Mitin
@DmytroMitin
@a_nigredo_twitter Well, this means that your Holder will not work.
Andrey Ivanov
@a_nigredo_twitter
it works, I use it already in some projects
let me create an example
Dmytro Mitin
@DmytroMitin
@a_nigredo_twitter It works with Strings, it won't work with Symbols.
Andrey Ivanov
@a_nigredo_twitter
I can convert keys to string via map
   object toName extends Poly1 {
      implicit def keyToName[A] = at[Symbol with A](x => Name(x.name))
    }
keys.map(toName)
then code will be
   object toName extends Poly1 {
      implicit def keyToName[A] = at[Symbol with A](x => Name(x.name))
    }
keys.map(toName).foldLeft(Holder)(???)
So I will have String::String::StringN::HNil which I should fold into Holder
Dmytro Mitin
@DmytroMitin
@a_nigredo_twitter You lost type information. keys had type (Symbol @@ "int") :: (Symbol @@ "long") :: HNil. Name(x.name) has type NameR[x.name.type] (if such type existed, x is not stable prefix). x doesn't have sense outside its scope. So keys.map(toName) has existential type NameR[_ <: String with Singleton] :: NameR[_ <: String with Singleton] :: HNil, it doesn't have type "int" :: "long" :: HNil, which your Holder could work with.
Andrey Ivanov
@a_nigredo_twitter
So it is not possible to implement what I want. Right?
Dmytro Mitin
@DmytroMitin
@a_nigredo_twitter Well, everything is possible (especially with macros). Your problem is not with foldLeft and Poly. Your problem is with Holder.
Andrey Ivanov
@a_nigredo_twitter
ok, I'll use macro
Dmytro Mitin
@DmytroMitin

@a_nigredo_twitter Well, I didn't say that you need a macro. I just said that currently your Holder works with Strings and not with Symbols. Can you make

val fields = Holder.add('int).add('long)
fields.select('int)

work? It's possible that Witness will be enough.

Andrey Ivanov
@a_nigredo_twitter
@DmytroMitin I'll try to implement asap
Luis Furnas
@luisfurnas
Record.`'id -> String`.T
This doesn't work anymore
Ben Spencer
@dangerousben
is there a way to tell the compiler that a type A is "a function of some kind" to take advantage of automatic eta-expansion?
eg if I have something like def foo[A, In, Out](a: A)(implicit f2p: FnToProduct.Aux[A, In => Out]) = ???
and then want to call it with a method and not have to mess around with (method _)
Paul Snively
@paul-snively
Hi everyone! I was just playing with Zipper, and it claims to work with "any type that has a Generic representation," but that appears to be false. In particular, we don't get .toZipper on a List[A], even though List[A] is correctly represented Genericly as a Coproduct of :: and Nil.
This means that, e.g. if I have a case class with a List element, I can't move down into the List: there's no Down instance available.