Questions tagged [shapeless]

shapeless is (an exploration of) a type class and dependent type based generic (aka polytypic/polymorphic) programming library for Scala.

shapeless is (an exploration of) a type class and dependent type based generic (aka polytypic/polymorphic) programming library for Scala derived from the various talks Miles Sabin has given over the course of 2011 on implementing scrap your boilerplate and higher rank polymorphism in Scala.

shapeless is an Open Source project under the Apache License v2.

1030 questions
0
votes
0 answers

Checksum at the Type Level using Shapeless

I came up with the following per this problem: package net import shapeless.{::, HNil, _} import ops.hlist.IsHCons import nat._ import ops.nat.{Mod, Prod, Sum} trait IsValid[A] object IsValid { def apply[L <: HList](implicit ev: IsValid[L]) =…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
1 answer

copy method and subtype polymorphism in Scala

I am trying to solve the following Scala compiler error below. case class CC[E](l:List[E]) trait D[E,L<:CC[E]]{ def f(l:L):L = l.copy(l=List()) // does not compile: "found CC[E], required: L" } In (pseudo)-Haskell (without sub-typing) this would…
jhegedus
  • 20,244
  • 16
  • 99
  • 167
0
votes
0 answers

Pattern Match on Coproduct?

Given the following from the Shapeless Guide: import shapeless.{Coproduct, :+:, CNil, Inl, Inr} case class Red() case class Amber() case class Green() type Light = Red :+: Amber :+: Green :+: CNil I tried to pattern match on Light: scala> def f(l:…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
0 answers

Using shapeless to implement filter

I'm trying to implement a filter such as the one described in this gist (please see the last comment). I want to wrap the salad bowl into a Fruits class, like this: scala> class Fruits[L <: HList](val bowl: FruitBowl[L]) I then want to create…
MMacphail
  • 541
  • 3
  • 19
0
votes
1 answer

Omit intermediate types in function signature

I would like to perfom two maps over shapeless HList, I have folllowing code that works: object doubleToInt extends Poly1 { implicit def caseDouble = at[Double](_.toInt) } object intToDouble extends Poly1 { implicit def caseInt =…
Krever
  • 1,371
  • 1
  • 13
  • 32
0
votes
1 answer

How to fix this compilation error with a Poly function

I am trying to map an HList of Xor to an HList of ValidatedNel and got an error: scala> type Result[A] = Xor[String, A] defined type alias Result scala> type Validation[A] = ValidatedNel[String, A] defined type alias Validation scala> val r0 =…
Michael
  • 41,026
  • 70
  • 193
  • 341
0
votes
1 answer

Enforce Bounded Nat?

How can I enforce a Nat that's <= N? Example: def lessThan5(x: NatLT5) = ??? where lessThan5(Nat(4)) would compile, but lessThan5(Nat(6)) would not.
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
0 answers

Get field names and values from LablelledGenerics of a case class

I try to have Seq[String], containing the fields name of a case class And another Seq[String] containing values of case class. In a generic way. I think I will have to map values with a Poly1 function to have the Arbitrary type => String. But now,…
crak
  • 1,635
  • 2
  • 17
  • 33
0
votes
1 answer

Map single type HList to HList of target types

I have trait-marker trait TypedTrait { type TYPE } and the realization case class TypedString[U](value: String) extends TypedTrait { type TYPE = U } And I want to map HList of String into HList of TypedString in accordance with TypedString's…
St.
  • 521
  • 3
  • 8
0
votes
1 answer

Diverging Implicits for Case Class w/ Case Class Argument

Given the following from Travis Brown's educational and well-written Type classes and generic derivation: case class Person(name: String, age: Double) trait Parser[A] { def apply(s: String): Option[A] } implicit val hnilParser:…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
0 answers

Scala: Copying a Case Class into another using Trait pointers

This question is similar to this one, except that both case class instances need to be accessed with references to their base trait. The reason for this is that more than one case class will be extending the trait, and the exact type won't be known…
Cigogne Eveillée
  • 2,178
  • 22
  • 36
0
votes
1 answer

Scala: Convert a Sealed Trait instance to an HList

Consider the following: sealed trait baseData { def weight: Int def priority: Int } case class data1(override val weight: Int, override val priority: Int) extends baseData How would I define a function with the following signature that…
Cigogne Eveillée
  • 2,178
  • 22
  • 36
0
votes
1 answer

Scala: Copying a generic case class into another

I have the following setup, where I want to copy an instance of baseData into that of moreData: sealed trait baseData { def weight: Int def priority: Int } sealed trait moreData { def weight: Int def priority: Int def t: String def id:…
Cigogne Eveillée
  • 2,178
  • 22
  • 36
0
votes
1 answer

Create HMap from HList type

Given a type parameter that is an HList, I want to create a HMap with the typeTags of the HList's types as keys, like this: (doesn't have to be a typeTag, just something that can hold the type) def createMap[L <: HList](valueFunction:...):HMap = { …
eirirlar
  • 814
  • 6
  • 24
0
votes
1 answer

Map for generic HList

Say we have following method def func[T <: HList](hlist: T, poly: Poly) (implicit mapper : Mapper[poly.type, T]): Unit = { hlist map poly } and custom Poly object f extends (Set ~>> String) { def apply[T](s : Set[T]) =…
St.
  • 521
  • 3
  • 8