Skip to main content
Filter by
Sorted by
Tagged with
3 votes
2 answers
101 views

Consider the following code: template<typename T> struct Ambiguous_C { void func(T); }; struct Ambiguous_F { template<typename T> void func(T); }; struct Conflicted_F : ...
Rddvldny's user avatar
0 votes
1 answer
189 views

In Scala 3, I'm able to write a poly-function of type 1: val y = [C <: Int] => (x: C) => x * 2 When I try to generalise it into type 2: val z = [C <: Int] => ([D <: Int] => (...
tribbloid's user avatar
  • 3,792
0 votes
2 answers
98 views

In the example below, I'm wondering why funPoly can't accept the existentially quantified type value outersFromInnersEx, even though funEx can. case class InnerCassClass[I, E, O](i: I, e: E, o: O) ...
bbarker's user avatar
  • 13.4k
3 votes
2 answers
536 views

Since Scala 2.12 (or is it 2.13, can't be sure), the compiler can infer latent type arguments across multiple methods: def commutative[ A, B ]: ((A, B) => (B, A)) = {???} // ...
tribbloid's user avatar
  • 3,792
0 votes
1 answer
83 views

Assuming if I have the following Record typed data, and a hlist of keys: val rr = ("a" ->> 1) :: ("b" -> "s") :: ("c" -> 3) :: ...
tribbloid's user avatar
  • 3,792
1 vote
1 answer
614 views

I have a situation where none of the solutions that I'm aware of feel like good ones. I am trying to define a typeclass, like the example below, where it has an abstract type S that must implement ...
Chris J Harris's user avatar
0 votes
2 answers
140 views

Question How to convert the method timed into a function? val timing = new StringBuffer def timed[T](label: String, code: => T): T = { val start = System.currentTimeMillis() val result = code ...
mon's user avatar
  • 23k
1 vote
1 answer
777 views

I'm trying to use Shapeless Poly in another method like this: object poly extends Poly1 { implicit val caseInt = at[Int](_.toString) implicit val caseString = at[String](_.toString) } def f[A, P ...
Minh Thai's user avatar
  • 578
0 votes
2 answers
57 views

I have this polymorphic function: def findFirst[A](as: Array[A], p: A => Boolean): Int = { @annotation.tailrec def loop(n: Int): Int = { if(n >= as.length) -1 else if(p(...
Sam Bean's user avatar
1 vote
2 answers
280 views

I came across this function iter p f x = if (p x) then x else (iter p f (f x)) and I thought I'd give a go at defining the polymorphic types myself to understand the concept. My thought was the ...
James's user avatar
  • 277
5 votes
2 answers
5k views

I do not see the bug in this implementation: CREATE FUNCTION foo(anyelement) RETURNS SETOF int AS $f$ SELECT id FROM unnest(array[1,2,3]) t(id) WHERE CASE WHEN (pg_typeof($1)::text)='...
Peter Krauss's user avatar
  • 14.1k
3 votes
2 answers
1k views

Let's say I need different output depending on the type of the polymorphic parameter of a function. My initial attempt fails with some cryptic error message: choice :: a -> Int choice (_ :: Int) = ...
mucaho's user avatar
  • 2,179
8 votes
1 answer
1k views

For example, how can I write a version of map that will work with polymorphic functions in Typed Racket? I use a simple id function defined as: (: id : (All (A) A -> A)) (define (id x) x) When I ...
Danil Gaponov's user avatar
3 votes
0 answers
495 views

I'm trying to solve this problem and want to fold over an HList using a Poly2 function. Here's a self-contained MWE (you can copy-paste this inside a REPL with shapeless 2.0 in order to reproduce the ...
Gabriele Petronella's user avatar
4 votes
2 answers
1k views

A polymorphic inline cache(PIC) works by caching the actual method by the type of the object, in order to avoid the expensive lookup procedures (usually a hashtable lookup). How does one handle the ...
user85408's user avatar