Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 09 11:48
  • Dec 09 11:38
  • Dec 09 11:25
    codecov-io commented #803
  • Dec 09 11:25
    joroKr21 synchronize #803
  • Dec 09 11:16
    codecov-io commented #798
  • Dec 09 11:16
    joroKr21 synchronize #798
  • Dec 09 10:48
    Travis milessabin/shapeless (master) passed (2683)
  • Dec 09 10:25

    milessabin on master

    Fix Typeable.describe for symbo… Merge pull request #945 from jo… (compare)

  • Dec 09 10:25
    milessabin closed #945
  • Dec 09 10:25
    milessabin closed #944
  • Dec 09 10:25
    milessabin commented #945
  • Dec 08 19:26
  • Dec 08 19:03
    joroKr21 edited #945
  • Dec 08 19:03
    joroKr21 opened #945
  • Dec 08 15:59
    milessabin closed #942
  • Dec 08 15:54
    ashleymercer commented #942
  • Dec 08 15:48
    milessabin commented #943
  • Dec 08 15:45
    milessabin commented #942
  • Dec 08 15:14
    joroKr21 commented #942
  • Dec 08 15:13
    joroKr21 commented #942
Ethan
@esuntag
def check[A, C <: Coproduct, K <: HList](data: Seq[A])(
    implicit
    gen: LabelledGeneric.Aux[A,C]
    keys: ops.union.Keys.Aux[C,K]
    toList: ops.hlist.ToTraversable.Aux[K,List,Symbol]
): List[(String,Boolean)] = {
    val classes: List[Symbol] = toList(keys())
    classes.map(sym => (sym.name, data.exists(_.getClass.getSimpleName == sym.name)))
}
Ethan
@esuntag
It does what I need it to, but feels dirty
rquinlivan
@rquinlivan
Hey guys, I'm trying to use shapeless's HMap class, and I'm running into trouble. The docs say that it supports "an arbitrary relation between the key type and the corresponding value type", but it looks like you cannot reuse the key type. I.e., you cannot define both a Int -> Double and Int -> String. Is this correct? Or am I using the library incorrectly?
Fabio Labella
@SystemFw
@rquinlivan yeah the point of HMap is to encode a unique relationship
if you have both Rel[Int, Double] and Rel[Int, String], and you do get(1), how will the typesystem know whether the value is of type Double or String?
you might also want to look at the vault library for a similar abstraction with different constraints
in that case the keys are represented by a value of type Key[A], and then you can get the corresponding value
it's not quite a Map though, more like a store
Cary Robbins
@carymrobbins
Maybe you could newtype the Int?
and just not use Int in the HMap
although it does seem like you might be able to do this if you specify the return type as well (not sure if that would work with HMap, but some sort of Poly wrapper around a Map should do it)
Ben Kyrlach
@bkyrlach
Say I have two HLists, H and I.
I can use implicit ev: SelectAll[H,I] to ensure all members of I are in H.
And I can use implicit ev: IsHCons[I] to ensure that I is not empty.
But if I combine the two like so...
def foo[H <: Hlist, I <: HList](xs: H, ys: I)(implicit ev: SelectAll[H,I], ev2: IsHCons[I]): Unit = {
  println(xs.select[ev2.H])
}
It says that there's no proof that ev2.H is in H.
Gunnar Lilleaasen
@heksesang
@bkyrlach Because ev2 contains proof that I has a head, but not that H has a head, I think.
Gunnar Lilleaasen
@heksesang
And you try to do a select without having a selector.
SelectAll does not guarantee order, so SelectAll[H, I] does not provide proof that IsHCons[I] is equal to IsHCons[H].
Gunnar Lilleaasen
@heksesang
So you cannot do ev2.head(xs) because while they have the same types, it’s not given that the head of H is the same type as head of I. It could be a type not existing in I, or one of the types in the tail of I. And if you wanna do xs.select, you need to provide a Selector instance for it.
Ben Kyrlach
@bkyrlach
I need to digest that a little.
But it looks way better than what I finally arrived at last night.
rquinlivan
@rquinlivan
To me the point of HMap would be to be able to get("key") and get back a strongly typed value instead of Any. If you cannot have polymorphic key mapping then HMap is useless.
Fabio Labella
@SystemFw
but that's what HMap does
or rather, there are two different approaches to this problem: HMap and Vault
rquinlivan
@rquinlivan
No, it gives you a mapping from A -> B and C -> D. Not A ->B and A -> C
Fabio Labella
@SystemFw
HMap is type driven
if you have A -> B and A -> C then by definition it's not a mapping
what does A ->map to, at the type level?
B or C?
rquinlivan
@rquinlivan
As far as practical usefulness, the way HMap is implemented is not useful.
Fabio Labella
@SystemFw
that's untrue, it's just not a good fit (maybe) for your current use case
rquinlivan
@rquinlivan
What is a use case where you would use it as it is implemented?
Fabio Labella
@SystemFw
use objects as your keys
they will all have different types
and it will work brilliantly
you can then convert strings to objects at the edge (or even build some machinery with witness similarly to how record selection works)
again, if you have A -> B and A -> C, how is that a mapping?
Fabio Labella
@SystemFw
btw I think there might be some confusion about the sort of guarantees that you can provide with static types in a language without full dependent types
it sounds like you want to be able to map the value "a" to the type Boolean and the value "b" to the type Int
this is not directly possible without full dependent types: a value is a runtime entity, whilst a type is a compile time one
the way you simulate it generally is by the pattern of creating singleton types
you create types with exactly one value, provide a type to type mapping, and then need to handle the lifting of values to their singleton types with runtime checks (if they aren't statically known) or macros (if they are)
the pattern I mention above with objects as key + HMap does exactly that
and the same pattern is used by shapeless labelled generic, without going through objects but directly exposing the singleton types of strings through macro magic
Fabio Labella
@SystemFw
@rquinlivan
Tim Spence
@TimWSpence

If I have a recursively-resolved typeclass like this:

trait Foo[A] {
  type Repr
  def to: Repr
}

With at most one instance for a given A. Is there a way to write an instance summoner that looks something like this:

def instance[A](implicit foo: Foo.Aux[A,R]): R = ???

? And if so, will the compiler correctly infer the concrete type rather than some Foo.Aux… type?

Fabio Labella
@SystemFw
def instance[A](implicit foo: Foo[A]): foo.Repr = foo