context-bound Questions

3

Solved

Suppose I have some function that should take a sequence of Ints or a sequence of Strings. My attempt: object Example extends App { import scala.util.Random val rand: Random.type = scala.util.R...
Henrique asked 13/6, 2020 at 19:26

1

In my library, I have three type classes: trait Monoid[T] { val zero : T def sum(x : T, y : T) : T } trait AbelianGroup[T] extends Monoid[T] { def inverse(x : T) : T def difference(x : T, y :...
Flop asked 29/7, 2015 at 4:48

2

Solved

I have some code like this: class ReflectiveJsonFormat[T:TypeTag] extends JsonFormat[T] { def write(x: T) : JsValue = { val t = typeOf[T] val getters = t.declarations.filter { s => s.isMetho...
Vashtivashtia asked 10/9, 2013 at 21:48

2

def bar[T: Manifest](a: Array[T]) = Array.ofDim[T](3) class Foo bar(Array(new Foo)) //Array[Foo] = Array(null, null, null) Manifests seem to exist implicitly for arbitrary types, as shown above...
Spark asked 18/11, 2011 at 23:43

1

Solved

One of the recent commits to Scala master removes restriction on combining context/view bounds with implicit parameters. That's a great improvement that reduces amount of boilerplate, but what was ...
Asteroid asked 26/7, 2011 at 21:30

3

Solved

Note: I'm posing this question to answer it myself, but other answers are welcome. Consider the following simple method: def add[T](x: T, y: T)(implicit num: Numeric[T]) = num.plus(x,y) I can r...
Pullman asked 7/12, 2010 at 3:15

2

Solved

Is it possible to use the context bounds syntax shortcut with higher kinded-types? trait One { def test[W : ClassManifest]: Unit } // first-order ok trait Two { def test[W[_]: ClassManifest]: Unit...
Diego asked 4/4, 2011 at 16:2

4

Solved

One of the new features of Scala 2.8 are context bounds. What is a context bound and where is it useful? Of course I searched first (and found for example this) but I couldn't find any really clea...
Boyse asked 5/6, 2010 at 22:1

2

Solved

In scala-arm project, I see code like this: def managed[A : Resource : Manifest](opener : => A) : ManagedResource[A] = new DefaultManagedResource(opener) Can someone explain the meaning of [A...
Outlander asked 26/9, 2010 at 14:51
1

© 2022 - 2024 — McMap. All rights reserved.