score:2
if i understood
but the
f[_]
declared at the instance level shadows thef[_]
declared at the test method (i want them to be the samef
)
correctly, you want your instance for sometypeclass[target[...]]
to fix the f[_]
parameter of test
. but that's simply not possible with this test
type signature. once you have (for example)
val inst = implicitly[sometypeclass[target[...]]
you can call
val res1 = inst.test[list, ...]
val res2 = inst.test[option, ...]
type lambdas don't offer a way around this problem. you need to either move f[_]
parameter to sometypeclass
or implement
implicit def instance[f[_]]: sometypeclass[target[f, *, *]] = new sometypeclass[target[f, *, *]] {
override def test[g[_], s, t, a, b](f: (a => g[b]) => s => g[t])
(pab: target[f, a, b])
(implicit ev: strong[target[f, *, *]],
ev2: choice[target[f, *, *]],
ev3: applicative[g]): target[g, s, t] = ???
}
which i expect is impossible as you can't pass pab.f
to f
.
edit: the type of wander
class (choice p, strong p) => traversing p where
traverse' :: traversable f => p a b -> p (f a) (f b)
traverse' = wander traverse
wander :: (forall f. applicative f => (a -> f b) -> s -> f t) -> p a b -> p s t
wander f pab = dimap (\s -> baz $ \afb -> f afb s) sold (traverse' pab)
is a rank-2 type which aren't supported in scala directly; instead you need to introduce a helper (which can't just be a type alias as it is in control.lens.type
)
trait traversal[s, t, a, b] {
def apply[f[_]: applicative](f: a => f[b]): s => f[t]
}
then
trait traversing[p[_, _]] extends strong[p] with choice[p] {
def wander[s, t, a, b](t: traversal[s, t, a, b], pab: p[a, b]): p[s, t]
}
implicit def instance[f[_]: applicative]: traversing[target[f, *, *]] = new traversing[target[f, *, *]] {
def wander[s, t, a, b](t: traversal[s, t, a, b], pab: target[f, a, b]): target[f, s, t] = target(t(pab.f))
// define strong and choice methods too
}
should work. (though i am not sure this is the cats way to deal with strong
and choice
requirements.)
Source: stackoverflow.com
Related Query
- kind-projector returns strange results
- Spark ML VectorAssembler returns strange output
- ArrayList and HashSet memory allocation strange test results
- Partially applied type lambda in Scala with kind projector
- What is a kind projector
- HBase FuzzyRowFilter returns no results
- Scala 2.8 vs 2.9 benchmark, strange results
- Strange results of `list.indexWhere` when parameter `from` is negative
- Strange results when using Scala collections
- foldLeft on List of Tuples: strange unexpected results
- sampleBy returns very skewed results
- Anorm returning 0 results while psql returns 2 results
- foldLeft on list of Doubles returns strange value
- scala-parser-combinators: opt() and "|" combination, strange results
- collect on hadoopFile RDD returns duplicate results
- Passing TableQuery object as a parameter results in strange type error in Slick/Scala but not when injected
- Scala Sets contain the same elements, but sameElements() returns false
- Scala: short form of pattern matching that returns Boolean
- Strange sbt bug where I cannot import sbt project due to keys colliding with themselves
- Scala foreach strange behaviour
- How to define a method in Scala that returns a Java object?
- How to cache results in scala?
- Spark Random Forests: Different results with same seed
- Ending a for-comprehension loop when a check on one of the items returns false
- strange error message: bad symbolic reference. A signature in package.class refers to term apache in package org which is not available
- Scala: Producing the intermediate results of a fold
- The strange case of multiple Futures in Scala
- Print out Scala worksheet results in interactive mode in IntelliJ
- What kind of data structure is used for immutable maps?
- Asking for a type's kind in Scala vs Haskell
More Query from same tag
- java-library does not expose scala classes
- Unifying view bounds within classes
- Unable to Analyse data
- Do scalac "-deprecation" and "-unchecked" compiler options make it slower
- Spark Submit Succeeded but Airflow Bash Operator Fail with Exit Code 127
- Spark: show and collect-println giving different outputs
- A better algorithm to find the next palindrome in Scala
- DBAction causes play server not responding
- How to do Integrated Windows Authentication (IWA) in a scala play web application
- How to hide a parameter in swagger?
- Play framework only Error: object httpclient is not a member of package org.apache.commons
- How to implement String contains with equals ignore case to filter content of a dataframe?
- Spark dataset: return a HashMap of values having same key
- "java.lang.IllegalAccessError" while reading multiline json file in Spark2.0
- How to return correct type from an overriden method in Scala?
- Json format - scala
- java.lang.NoClassDefFoundError: Could not initialize class - spark/scala
- Accessing radio button values from controller
- Standard way around unimplemented getBlob in xerial/SQLIte for Slick/Scala?
- type keyword in scala file upload exampe
- What is the difference between Mongo Scala Driver and Reactive-Mongo Driver in play framework?
- Can I make http redirect using 403 ( forbidden )?
- How to output field padding in file Scala spark?
- Spark program behave differently based on --master is set to local[4] or yarn-client
- Scala create array of empty arrays
- Serialization exception in HazelCast 3.5 with Scala
- SASS Not Reloading with Play 2.0
- How to extract response data in Gatling
- "/packages cannot be represented as URI"
- Return type of Scala for/yield