29 questions
3
votes
2
answers
101
views
Template resolution in method with a class template parameter is not working when using multiple inheritance in base class. Why? How?
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 : ...
0
votes
1
answer
189
views
How to write curried polymorphic function & its higher kind in Scala 3?
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] => (...
0
votes
2
answers
98
views
Why can't a polymorphic function accept wildcard (existential) types in Scala?
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)
...
3
votes
2
answers
536
views
In Scala, how to summon a polymorphic function applicable to an input type, without knowing the output type or full type arguments?
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)) = {???} // ...
0
votes
1
answer
83
views
Can shapeless Record type be used as a Poly1?
Assuming if I have the following Record typed data, and a hlist of keys:
val rr = ("a" ->> 1) ::
("b" -> "s") ::
("c" -> 3) ::
...
1
vote
1
answer
614
views
Defining a constructor for a typeclass that takes a method with a type parameter?
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 ...
0
votes
2
answers
140
views
How to convert a generic method into generic function
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
...
1
vote
1
answer
777
views
Using Shapeless Poly in another method
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 ...
0
votes
2
answers
57
views
Pass Search term and Operator to Scala Polymorphic Function
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(...
1
vote
2
answers
280
views
Polymorphic types in Haskell
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 ...
5
votes
2
answers
5k
views
Function parameter anyelement, PostgreSQL bug?
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)='...
3
votes
2
answers
1k
views
Pattern match on type of polymorphic parameter - alternatives
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) = ...
8
votes
1
answer
1k
views
How do I write higher-order functions that take polymorphic functions as arguments in Typed Racket?
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 ...
3
votes
0
answers
495
views
Diverging implicit expansion for shapeless LeftFolder
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 ...
4
votes
2
answers
1k
views
How do polymorphic inline caches work with mutable types?
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 ...