Questions tagged [implicit-parameters]

28 questions
7
votes
1 answer

How to replace ImplicitParams with the 'reflection' package?

I have an enumeration type, e.g. data MyType = A | B And I want to be able to pass values of this type implicitly to my functions. I can do this using the ImplicitParams GHC extension like this: type HasMyType = (?myType :: MyType) myFun ::…
Shersh
  • 9,019
  • 3
  • 33
  • 61
6
votes
1 answer

Template Haskell and Implicit Parameters

Is there a way to create functions with implicit parameters or let bindings with implicit parameters using template haskell? I.e. is it possible to generate a signature like this using template haskell: doSomething :: (?context :: Context) => m…
scravy
  • 11,904
  • 14
  • 72
  • 127
5
votes
1 answer

Are implicit parameters a difficulty for inlining in GHC?

I'm curious about the objections to implicit parameters discussed in the Functional Pearl: Implicit Configurations article by Kiselyov and Shan. It is not sound to inline code (β-reduce) in the presence of implicit parameters. Really? I'd…
Jeff Burdges
  • 4,204
  • 23
  • 46
4
votes
1 answer

Scala apply method call as parentheses conflicts with implicit parameters

There is a note in Cay Horstmann's book "Scala for the Impatient" about the apply method: Occasionally, the () notation conflicts with another Scala feature: implicit parameters. For example, the expression "Bonjour".sorted(3) yields an error…
Guram Savinov
  • 594
  • 5
  • 10
3
votes
2 answers

Scala - Abstract types and Implicit Parameter Resolution

I'm using Scala 2.10.4. Please bare with the analogy - the actual code is deeply embedded in a complicated program, so rather than explain that, I’ll abstract the problem in a time honoured way to talk about Animals ;-) In scala I have 2 traits -…
Phil
  • 592
  • 6
  • 15
3
votes
2 answers

How to extend class with implicit parameter in Scala

class B(implicit imp: Int) extends AC { } object C extends B{ } Error: could not find implicit value for parameter imp This is what i was looking for: How to provide default value for implicit parameters at class level
Alex
  • 592
  • 4
  • 10
2
votes
2 answers

Is there no such thing as "implicit this parameter" in the Standard?

Recently, I asked this question where one of the answers says: There's no such thing as "implicit this parameter" in the standard. The standard calls it an "implicit object parameter". Then someone commented that: There's no such thing as…
Jason
  • 36,170
  • 5
  • 26
  • 60
2
votes
3 answers

Scala type constraint precedence in implicit resolution

I have these 2 implicits trait A[T] { val name: String } trait B object A { implicit def product[T <: Product] = new A[T] { override val name: String = "product" } implicit def childOfB[T <: Product with B] = new A[T] { override…
2
votes
1 answer

A function that sets an implicit parameter context

I've been mucking around with implicit parameters which I've sometimes found useful, but trying to do something like the code below (which doesn't compile) {-# LANGUAGE ImplicitParams #-} main = print (f z) f g = let ?x = 42 ?y = 5 …
Clinton
  • 22,361
  • 15
  • 67
  • 163
2
votes
1 answer

Use of an implicit parameter of type Numeric[A] seems to be ignored

Being new to Scala, I was playing around with fold, reduce and scan. I wanted to see the sequence in which elements are passed on the the function parameter and how the final result was being assembled. Since I planned to use it on lists of numbers…
sTievie
  • 65
  • 7
1
vote
0 answers

Compiler can't find implicit values even tho I've created the JsonProtocol

So I have this simple post endpoint where should happen some unmarshalling post { path("/emails") { import package.model.impl.RegularEmailJsonSupport._ entity(as[RegularEmail]) { regularEmail => …
Claudiu Scurtu
  • 183
  • 1
  • 1
  • 10
1
vote
1 answer

Idris2: Is there a way use implicits in interface implementations

I'm following TDD with Idris using Idris2. I'm in chapter 6 working on the DataStore with schema. First of all for some context: infixr 5 .+. data Schema = SString | SInt | (.+.) Schema Schema SchemaType : Schema ->…
Stefan Wullems
  • 743
  • 1
  • 7
  • 20
1
vote
2 answers

Default value for implicit parameter of class method

I want to have a sort of "transaction" construct, on which I'm doing all of the changes and then decide if to commit or rollback at the end. My issue is that I don't know how to properly define / pass the implicit values without defining them…
solyd
  • 782
  • 2
  • 8
  • 18
1
vote
1 answer

Calling primary constructor with multiple implicit parameters call from Java

I have a Scala class that returns the max of an input type IN using a MR job in Apache Spark. This class works fine if I call it from Scala and it works as follows: // Class class TypedMax[IN, T](val f: IN => T)(implicit ev$1: T => Ordered[T], ev$2:…
ScrubS
  • 11
  • 2
1
vote
1 answer

implicit parameters and generic types

i'm trying to understand the behavior of the compiler in this situation object ImplicitTest extends App { def foo[T](implicit x: (String => T)): T = ??? implicit val bar = (x: String) => x.toInt foo } the code above does not compile and…
Daniel Camarda
  • 1,126
  • 12
  • 18
1
2