Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 15 13:56
    Travis milessabin/shapeless (master) passed (2668)
  • Nov 15 13:32

    milessabin on master

    Clean up previous commit. (compare)

  • Nov 14 19:58
    Travis milessabin/shapeless (master) passed (2667)
  • Nov 14 19:31

    milessabin on master

    Macro paradise no longer needed… (compare)

  • Nov 04 14:51
    Travis milessabin/shapeless (master) passed (2666)
  • Nov 04 14:26

    milessabin on master

    Add tests for removeAll with du… Fix bug involving order of Remo… Merge pull request #937 from tr… (compare)

  • Nov 04 14:26
    milessabin closed #937
  • Nov 04 14:26
    milessabin closed #936
  • Nov 04 14:26
    milessabin commented #937
  • Nov 04 11:45
  • Nov 04 11:20
    travisbrown edited #937
  • Nov 04 11:20
    travisbrown opened #937
  • Nov 04 11:18
    travisbrown opened #936
  • Nov 01 10:45
    Travis milessabin/shapeless (master) passed (2664)
  • Nov 01 10:20

    milessabin on master

    Update slf4j-nop to 1.7.29 Merge pull request #935 from sc… (compare)

  • Nov 01 10:20
    milessabin closed #935
  • Nov 01 10:20
    milessabin commented #935
  • Nov 01 00:23
  • Oct 31 23:59
    scala-steward opened #935
  • Oct 28 19:46
    milessabin labeled #934
Paul Snively
@paul-snively
I suspect what you are trying here could actually be done by making L existential.
Andrey Ivanov
@a-nigredo
@paul-snively how can I set L as existential?
Paul Snively
@paul-snively
I don't know what good that would do you: you're presumably using HList because you want the specificity of Int :: Int :: HNil, so why the L <: HList in the first place?
I think something like type L = L forSome { type L <: HList }?
Andrey Ivanov
@a-nigredo
method above it is just a mock. My task is more complex.
ty, I'll try existential
Paul Snively
@paul-snively
Ah: def r[L]: L forSome { type L <: HList } = 1:: 2:: HNil.
Andrey Ivanov
@a-nigredo
it works, thanks. Could you please help me to fix another issue?
now when I call r and want to call map with poly function it does not compile
Error:(81, 106) could not find implicit value for parameter mapper: shapeless.ops.hlist.Mapper[foo.type,L]
    println(r(ticket).map(foo))
Paul Snively
@paul-snively
This is what I meant when I said you presumably want L not to be existential. :-)
Andrey Ivanov
@a-nigredo
So with existential it is not possible to call map?
Paul Snively
@paul-snively
I wouldn't expect so.
Mapper works by examining each type in the HList, which implies the HList in question must be concrete.
Your r compiles, but isn't really useful: it just says "Here comes some HList."
What HList? You don't know.
Andrey Ivanov
@a-nigredo
ok, thank you very much for helping. I'll think about another implementation way
Paul Snively
@paul-snively
Sure. May I ask what you're trying to do?
I presume r doesn't represent what you really want to do.
(There's not much point to a constant function that pretends it doesn't know what it's returning.)
Andrey Ivanov
@a-nigredo
give me some time I'll create a gist and share it
Paul Snively
@paul-snively
Sure thing!
Fabio Labella
@SystemFw
Do not go into existentials unless you know exactly what you're doing, more often than not that path will lead you astray :) (but it's invaluable when you actually need it)
Paul Snively
@paul-snively
Right. "There is some type. It exists. That's all you know."
Fabio Labella
@SystemFw

def r[L<: HList]: L = 1:: 2:: HNil

when you are dealing with parametric polymorphism ("generics"), you can view type parameters in that position as a promise to the caller that you work forall L, and the caller get to choose
so in that code you are saying "no matter what L you choose, I can give you that same L so long as L is a subtype of HList". But then you are breaking your promise immediately by returning an Int (so you are trying to choose, rather than letting the caller do that).

Wanting to choose yourself is not always wrong, sometimes it's great (both existentials and higher-ranks are related to it), but unless you are doing it deliberately it's probably something going wrong at some point :)
Anyway I'll let you finish the gist

Fabio Labella
@SystemFw
you cannot do your first transformation statically
you are trying to compute at compile time something you only know at runtime (whether the Target is Rest or Batch)
so you will have to return an Either of the the hlists, rather than getting just the correct hlist at compile time
Paul Snively
@paul-snively
I was just going to suggest actually using Coproduct.
Then, instead of map, you'd fold over it.
Fabio Labella
@SystemFw
I think you get closer to what you need with a GADTs, assuming eventually everything resolves to a single type, but I'll have to know what are you actually trying to achieve (also GADTs can be fidgety in scala 2, although still useful)
Andrey Ivanov
@a-nigredo
ok, thank you guys, I'll take into account what you propose and try to implement it
Paul Snively
@paul-snively
@a-nigredo: It seems like you have "this or that," and want to handle all of the cases polymorphically, right?
Andrey Ivanov
@a-nigredo
@paul-snively yes and on type-level. So I have to put "or" to type-level as @SystemFw suggested via Either
Paul Snively
@paul-snively
@a-nigredo: I'm suggesting Coproduct because you can .fold a Poly over it. But it may be overkill if you're sure you'll only ever have two branches.
Andrey Ivanov
@a-nigredo
@paul-snively I've 5 branches now. I just took 2 for an example
Paul Snively
@paul-snively
@a-nigredo: Then Coproduct it is. :-D
Andrey Ivanov
@a-nigredo
ok
Paul Snively
@paul-snively
type Foo = A :+: B :+: C :+: D :+: E :+: CNil
val foo = Coproduct[Foo](myC)
Define a Poly with cases for A, B, C, D, and E.
Then foo.fold(myPoly).
Andrey Ivanov
@a-nigredo
cool, ty
Francisco Albert Albusac
@tatitati

guys, I'm trying Shapeless, from the book, and I'm following an example on it:

val a = Generic[Shape]
println(a) // shapelessSpecs.CoproductSpec$anon$macro$1$1@36e6a5e0

Is it possible to have the nice representation that appear in the book?, like:
CoproductSpec.this.Circle :+: CoproductSpec.this.Rectangle :+: shapeless.CNil

Paul Snively
@paul-snively
@tatitati: I think splain supports that.
Francisco Albert Albusac
@tatitati
ou...didn't know about them, thanks, having a look
Paul Snively
@paul-snively
splain is awesome.
Fabio Labella
@SystemFw
@tatitati you are mixing up types and values. The representation you want is what the type looks like (a bit uglier if you don't uses splain, but still). But if you print a, you get the value, i.e. the typeclass instance with the methods to and from
Francisco Albert Albusac
@tatitati
o...ok