Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 09 21:03
    joroKr21 synchronize #1240
  • Apr 07 16:55

    joroKr21 on main

    Update sbt-mima-plugin to 1.1.0 Merge pull request #1258 from s… (compare)

  • Apr 07 16:55
    joroKr21 closed #1258
  • Apr 07 16:47
    scala-steward opened #1258
  • Apr 05 06:02

    joroKr21 on main

    Update sbt-scalajs, scalajs-com… Merge pull request #1257 from s… (compare)

  • Apr 05 06:02
    joroKr21 closed #1257
  • Apr 05 02:57
    scala-steward opened #1257
  • Mar 27 15:42

    joroKr21 on v2.3.9

    (compare)

  • Mar 26 20:08
    joroKr21 closed #1254
  • Mar 26 20:08
    joroKr21 commented #1254
  • Mar 26 20:05

    joroKr21 on 2.3

    When case class has custom unap… Merge pull request #1256 from j… (compare)

  • Mar 26 20:05
    joroKr21 closed #1256
  • Mar 26 19:29
    joroKr21 synchronize #1256
  • Mar 26 18:51
    joroKr21 labeled #1256
  • Mar 26 18:51
    joroKr21 labeled #1256
  • Mar 26 18:51
    joroKr21 assigned #1256
  • Mar 26 18:51
    joroKr21 opened #1256
  • Mar 26 17:45

    joroKr21 on main

    When case class has custom unap… Merge pull request #1255 from j… (compare)

  • Mar 26 17:45
    joroKr21 closed #1255
  • Mar 26 17:45
    joroKr21 closed #1059
David Hoyt
@davidhoyt
@SystemFw yes, I was starting to go down the flatten path. I need this for labelled generics not basic (generic) products, so I tried to evolve the flatten example without much luck so far.
Fabio Labella
@SystemFw
I was doing it, but I hit an unrelated bug
I got a working version for Generic very quickly
but it didn't work for LabelledGeneric
which is really surprising, so I kept minimising and I think I've hit something that looks like a compiler bug
just posted in the scala room
David Hoyt
@davidhoyt
@SystemFw not surprised in the least. to make matters worse, I am needing it to work w/ shapeless 2.2.5 on scala 2.10 and 2.11 actually.
Fabio Labella
@SystemFw
oh, have fun :)
David Hoyt
@davidhoyt
i need a "miserable" emoji :D
Fabio Labella
@SystemFw
by "not work with LabelledGeneric" I meant they both compiled, but exhibited different behaviour
which it never happened to me with shapeless before, and I would say I'm fairly experienced with it
David Hoyt
@davidhoyt
@SystemFw do you mind pasting what you have in a scala fiddle or elsewhere?
Fabio Labella
@SystemFw
@davidhoyt what do you want exactly? the working version with Generic and the non-working one with LabelledGeneric?
David Hoyt
@davidhoyt
non-working one with labelled generic
Fabio Labella
@SystemFw
ah, I've deleted it, let me see if I can redo it
I had two versions, one with Poly, one with custom typeclasses
let me redo the one with Poly, it's shorter
David Hoyt
@davidhoyt
@SystemFw this may show my ignorance wrt shapeless -- i am trying to auto-derive type class instances. will that work w/ Poly?
Fabio Labella
@SystemFw
I also did versions with auto-derived type classes
same behaviour
David Hoyt
@davidhoyt
@SystemFw i suppose i'm asking if you can use Poly to derive type classes
Fabio Labella
@SystemFw
actually, when doing the typeclass version I got the other possible bug
@davidhoyt The question is a bit unclear to me
Poly exposes type class instances (Case), which you can use in your typeclass derivation
David Hoyt
@davidhoyt
@SystemFw i am saying that i've never used Poly that way -- i'm somewhere between beginner and intermediate level w/ shapeless
Fabio Labella
@SystemFw
similarly, some typeclasses you also use in derivations (e.g.Mapper, FlatMapper), want a Poly
@davidhoyt right, basically if you have something that works with Poly, you can ask for an implicit Case1 of that Poly
just like you would ask for another typeclass instance
(well, Case1, Case2...what have you)
or, you can write your own custom typeclass (which is what I do most of the time), to replace the poly
David Hoyt
@davidhoyt
@SystemFw i was going down that path primarily because i was unaware of alternatives :)
so I have a "wrapper" type class which I derive and can then turn into the actual type class I care about
Fabio Labella
@SystemFw
is there any reason for not deriving the type class you care about directly?
Fabio Labella
@SystemFw

TIL:

No, the subclass rule and the specificity of the type rule are both run and the score is tallied. If they are in opposite directions, it ends up with ambiguity.

So prioritising implicits to encode typelevel pattern matching precedence does not always work...disappointing

Fabio Labella
@SystemFw
apparently the further trick is make sure the specifity rule tally goes back to 0, so that the subclassing rule kicks back as the decisive factor
Fabio Labella
@SystemFw
@davidhoyt I'm close to solving your problem
David Hoyt
@davidhoyt
@SystemFw please share what you have -- i'd like to learn/collaborate
really appreciate your help
Ryan Williams
@ryan-williams

OT: can i get a Generic for a trait with only abstract fields? e.g. with a structure like this:

trait Foo { def a: A; def b: B; def c: C }
trait Bar extends Foo { def d: D }
trait Baz extends Foo { def e: E }

I want to be able to get Generics for Foo/Bar/Baz.

The context is that I'm trying to have multiple classes/traits share a set of fields while also being able to get a Generic for them, without having to repeat all the fields everywhere. traits can be composed to allow this but but classes/fields/ctor-args can't. cf. https://github.com/alexarchambault/case-app/issues/58#issuecomment-313799457

i'm considering trying to write a macro (annotation?) to do it. i guess some detail on the macro that shapeless uses to get Generics for case classes would be useful too; iirc it hangs off of the existence of a case class's apply method?
Fabio Labella
@SystemFw
@davidhoyt Sorry, had to go away. I have a Poly that flattens arbitrarily nested case classes , preserving the names of the fields in a type akin to a LabelledGeneric#Repr
  case class Foo(a: String, b: Bar)
  case class Bar(c: Int, d: Baz)
  case class Baz(e: Long)

  val v = Foo("A", Bar(1, Baz(2)))

  def a = flatten(v)
  res1: shapeless.::[String with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("a")],String],shapeless.::[Int with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("c")],Int],shapeless.::[Long with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("e")],Long],shapeless.HNil]]] = 
    A :: 1 :: 2 :: HNil
Fabio Labella
@SystemFw
Question: given a Poly f, I can implicitly ask for an instance of that poly for type parameter A by implicit ev: Case[A, f.type].
Provided the types line up, I can compose f with another poly g via object c extends Compose(f, g). How do I implicitly ask for an instance of the composed poly for type parameter A?
Fabio Labella
@SystemFw
nvm, figured it out (Case[c.type, A :: HNil])
@davidhoyt solved it!
David Hoyt
@davidhoyt
@SystemFw great thanks -- i just read all of dave gurnell's book on shapeless :)
@SystemFw please share!
Fabio Labella
@SystemFw
I did it with Polys to learn something different, I think it would have actually been easier (but more verbose), to figure out with just custom typeclasses, but here you go:
  import shapeless._, ops.hlist._, poly._, labelled._

  trait Describe[A] {
    def apply(a: A): String
  }
  object Describe {
    def apply[A](a: A)(implicit ev: Describe[A]) = ev(a).dropRight(2)

    implicit def all[A](
        implicit f: Case.Aux[body.type, A :: HNil, String]): Describe[A] =
      new Describe[A] {
        def apply(a: A) = f.apply(a)
      }
    object body extends Compose(describer, flatten)

    object describer extends LowPrioDescriber {
      implicit def all[H <: HList](
          implicit fm: MapFolder[H, String, describer.type]) =
        at[H](x => fm(x, "", _ + _))
    }
    trait LowPrioDescriber extends Poly1 {
      implicit def base[K <: Symbol, V](implicit key: Witness.Aux[K]) =
        at[FieldType[K, V]](x => s"${key.value.name} = ${x.toString}, ")
    }

    object flatten extends LowPrioFlatten {
      implicit def hlists[H <: HList](
          implicit fm: Lazy[FlatMapper[flatten.type, H]]) =
        at[H](x => fm.value(x))

      implicit def kv[K, V, R](implicit gen: LabelledGeneric.Aux[V, R],
                               rec: Lazy[Case1[flatten.type, R]]) =
        at[FieldType[K, V]](x => rec.value(gen.to(x)))

      implicit def prods[A, R <: HList](
          implicit gen: LabelledGeneric.Aux[A, R],
          rec: Lazy[Case1[flatten.type, R]]) =
        at[A](x => rec.value(gen.to(x)))
    }
    trait LowPrioFlatten extends Poly1 {
      implicit def all[A] = at[A](x => x :: HNil)
    }
  }
example:
  case class Foo(a: String, b: Bar)
  case class Bar(c: Int, d: Baz)
  case class Baz(e: Long)

  val v = Foo("A", Bar(1, Baz(2)))

  def c = Describe(v)
 // res1: String = a = A, c = 1, e = 2