Questions tagged [context-bound]

Context bounds were introduced in Scala 2.8.0, and are typically used with the so-called type class pattern, a pattern of code that emulates the functionality provided by Haskell type classes, though in a more verbose manner.

Context bounds were introduced in Scala 2.8.0, and are typically used with the so-called type class pattern, a pattern of code that emulates the functionality provided by Haskell type classes, though in a more verbose manner.

References

Related Tags

55 questions
0
votes
1 answer

Typeclasses methods called in functions with type parameters

I'm trying to use a typeclass method inside a function with a type parameter. Unfortunately I can't get it to work. When I try to use the method addRegisterInOut the compiler throws an error on the following code. class Module extends Component { …
0
votes
1 answer

How to resolve implicit lookup by bounded generic?

I have a series of class Foo: trait Foo class Foo1 extends Foo class Foo2 extends Foo //... and I have a type class and instances for all of the Foos: trait CanBar[T] { def bar: Unit } implicit val foo1: CanBar[Foo1] = null implicit val foo2:…
SwiftMango
  • 15,092
  • 13
  • 71
  • 136
0
votes
1 answer

Scala - Method type parameters

I'm trying to understand some autogenerated code by the scala compiler but I don't know after what to search. I have the following class: trait Arrow1[F[_, _]] abstract class Test { def f1[F[_, _] : Arrow1, A, B, C](fa: F[A,B], fb: F[A, C]):…
Octavian R.
  • 1,231
  • 8
  • 12
0
votes
1 answer

Context bound for varargs

Few days ago I started to learn Cats and I want to implement method appendOptional for Map[String, _: Show]. I started with the following idea: def appendOptional[T: Show](to: Map[String, String], values: (String, Option[T])*): Map[String, String] =…
Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
0
votes
1 answer

In Scala, how to create a trait for classes with functions using different context bounds

Now I wanna serialize/deserialize Json data, and there are several json libraries to choose. However, they use different context-bounds for encoding/decoding, which make it hard to define a trait for them. trait JsonLib { // def writes[T](data:…
Ringo
  • 3
  • 1
0
votes
2 answers

Scala context bounds

Using context bounds in scala you can do stuff like trait HasBuild[T] { def build(buildable: T): Something } object Builders { implict object IntBuilder extends HasBuild[Int] { override def build(i: Int) = ??? // Construct a Something…
Balázs Édes
  • 13,452
  • 6
  • 54
  • 89
0
votes
1 answer

Scala: Triple Context Bounds, evidence parameters not found

I have edited this to a simpler form of the question to which @Zhi Yuan Wang responded : object ContBound { def f2[A: Seq, B: Seq]: Unit = { val a1: Seq[A] = evidence$1 val b2: Seq[B] = evidence$2 } def f3[A: Seq, B: Seq, C:…
Rich Oliver
  • 6,001
  • 4
  • 34
  • 57
0
votes
2 answers

Play Action Composition - hardcoding parameterized parser

I would like to create a custom action which takes away the boilerplate of writing actions like this: Action[MyClass](BodyParsers.parse.json[MyClass]) { req => ... However, I keep running into class definition errors. Here has been my most…
TheDarkSaint
  • 457
  • 3
  • 13
0
votes
2 answers

solving multiple inheritance (for precooked classes)

What I need: a class with two parents, which are ContextBoundObject and another class. Why: I need to access the ContextBoundOject to log the method calls. Composition works? As of now, no (types are not recognized, among other things). Are other…
lunadir
  • 339
  • 3
  • 15
0
votes
1 answer

Scala: hierarchy of typeclasses and implicit resolution

Suppose I'm trying to represent, say, the domain of boolean logic (ignoring reduction for now). So I'll have in my store instances of Bools, or Ands and Ors or Nots etc. However, whilst I'll have concrete representations for these things, in many…
Submonoid
  • 2,809
  • 2
  • 20
  • 25
1 2 3
4