Implicit for Function not being foundPimp my function in scala - applying implicit conversions on functionsWhere does Scala look for implicits?How can a time function exist in functional programming?selecting a subset of a list of functions based off of the type of their arguments in scalaCovariance of a passed function argumentScala: Is it possible to override val's in the sub-class's constructor?Scala ambiguity with paren-less function callsImporting implicits from a subclassUnable to find implicit macroWhere to put implicits and helper functions, traits vs companion objects
Why is long-term living in Almost-Earth causing severe health problems?
How can one's career as a reviewer be ended?
Do you have to have figures when playing D&D?
How can powerful telekinesis avoid violating Newton's 3rd Law?
What is Gilligan's full Name?
Why is the length of the Kelvin unit of temperature equal to that of the Celsius unit?
Why did the World Bank set the global poverty line at $1.90?
Who is "He that flies" in Lord of the Rings?
Confused with atmospheric pressure equals plastic balloon’s inner pressure
How can I remove material from this wood beam?
Breaking changes to eieio in Emacs 27?
Remove border lines of SRTM tiles rendered as hillshade
If someone intimidates another person, does the person affected gain the Frightened condition?
How (un)safe is it to ride barefoot?
Proving that a Russian cryptographic standard is too structured
C++ logging library
How to avoid typing 'git' at the begining of every Git command
Was Self-modifying-code possible just using BASIC?
Why would a home insurer offer a discount based on credit score?
How far would a landing Airbus A380 go until it stops with no brakes?
Augment Export function to support custom number formatting
Should I refuse to be named as co-author of a low quality paper?
Suppose leased car is totalled: what are financial implications?
The origin of the Russian proverb about two hares
Implicit for Function not being found
Pimp my function in scala - applying implicit conversions on functionsWhere does Scala look for implicits?How can a time function exist in functional programming?selecting a subset of a list of functions based off of the type of their arguments in scalaCovariance of a passed function argumentScala: Is it possible to override val's in the sub-class's constructor?Scala ambiguity with paren-less function callsImporting implicits from a subclassUnable to find implicit macroWhere to put implicits and helper functions, traits vs companion objects
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have this typeclass
import simulacrum._
@typeclass trait Functor[F[_]]
def map[A, B](fa: F[A])(f: A => B) : F[B]
def lift[A, B](fa: F[A])(f: A => B) : F[A] => F[B] = fa => map(fa)(f)
def as[A, B](fa: F[A], b: => B) : F[B] = map(fa)(_ => b)
def void[A](fa: F[A]) : F[Unit] = as(fa, ())
and this is the implementation
object Functor
implicit val listFunctor: Functor[List] = new Functor[List]
def map[A, B](fa: List[A])(f: A => B) = fa.map(f)
implicit def functionFunctor[X]: Functor[X => ?] = new Functor[X => ?]
def map[A, B](fa : X => A)(f : A => B) = fa andThen f
I can easily discover the List implicit implementation as
object Chapter1 extends App
import Functor.ops._
List(1, 2, 3).as("foo").foreach(println)
The above works perfectly fine. I can also do
object Chapter1 extends App
import Functor._
val func : Int => String = implicitly[Functor[Int => ?]].map(_ + 2)(_.toString)
println(func(5))
But when I try
object Chapter1 extends App
import Functor.ops._
val x : Int => Int = _ + 2
val y : Int => String = x.map(_.toString)
It doesn't find my implicit implementation and says that the value map
is not a member of Int => Int
scala simulacrum
add a comment |
I have this typeclass
import simulacrum._
@typeclass trait Functor[F[_]]
def map[A, B](fa: F[A])(f: A => B) : F[B]
def lift[A, B](fa: F[A])(f: A => B) : F[A] => F[B] = fa => map(fa)(f)
def as[A, B](fa: F[A], b: => B) : F[B] = map(fa)(_ => b)
def void[A](fa: F[A]) : F[Unit] = as(fa, ())
and this is the implementation
object Functor
implicit val listFunctor: Functor[List] = new Functor[List]
def map[A, B](fa: List[A])(f: A => B) = fa.map(f)
implicit def functionFunctor[X]: Functor[X => ?] = new Functor[X => ?]
def map[A, B](fa : X => A)(f : A => B) = fa andThen f
I can easily discover the List implicit implementation as
object Chapter1 extends App
import Functor.ops._
List(1, 2, 3).as("foo").foreach(println)
The above works perfectly fine. I can also do
object Chapter1 extends App
import Functor._
val func : Int => String = implicitly[Functor[Int => ?]].map(_ + 2)(_.toString)
println(func(5))
But when I try
object Chapter1 extends App
import Functor.ops._
val x : Int => Int = _ + 2
val y : Int => String = x.map(_.toString)
It doesn't find my implicit implementation and says that the value map
is not a member of Int => Int
scala simulacrum
add a comment |
I have this typeclass
import simulacrum._
@typeclass trait Functor[F[_]]
def map[A, B](fa: F[A])(f: A => B) : F[B]
def lift[A, B](fa: F[A])(f: A => B) : F[A] => F[B] = fa => map(fa)(f)
def as[A, B](fa: F[A], b: => B) : F[B] = map(fa)(_ => b)
def void[A](fa: F[A]) : F[Unit] = as(fa, ())
and this is the implementation
object Functor
implicit val listFunctor: Functor[List] = new Functor[List]
def map[A, B](fa: List[A])(f: A => B) = fa.map(f)
implicit def functionFunctor[X]: Functor[X => ?] = new Functor[X => ?]
def map[A, B](fa : X => A)(f : A => B) = fa andThen f
I can easily discover the List implicit implementation as
object Chapter1 extends App
import Functor.ops._
List(1, 2, 3).as("foo").foreach(println)
The above works perfectly fine. I can also do
object Chapter1 extends App
import Functor._
val func : Int => String = implicitly[Functor[Int => ?]].map(_ + 2)(_.toString)
println(func(5))
But when I try
object Chapter1 extends App
import Functor.ops._
val x : Int => Int = _ + 2
val y : Int => String = x.map(_.toString)
It doesn't find my implicit implementation and says that the value map
is not a member of Int => Int
scala simulacrum
I have this typeclass
import simulacrum._
@typeclass trait Functor[F[_]]
def map[A, B](fa: F[A])(f: A => B) : F[B]
def lift[A, B](fa: F[A])(f: A => B) : F[A] => F[B] = fa => map(fa)(f)
def as[A, B](fa: F[A], b: => B) : F[B] = map(fa)(_ => b)
def void[A](fa: F[A]) : F[Unit] = as(fa, ())
and this is the implementation
object Functor
implicit val listFunctor: Functor[List] = new Functor[List]
def map[A, B](fa: List[A])(f: A => B) = fa.map(f)
implicit def functionFunctor[X]: Functor[X => ?] = new Functor[X => ?]
def map[A, B](fa : X => A)(f : A => B) = fa andThen f
I can easily discover the List implicit implementation as
object Chapter1 extends App
import Functor.ops._
List(1, 2, 3).as("foo").foreach(println)
The above works perfectly fine. I can also do
object Chapter1 extends App
import Functor._
val func : Int => String = implicitly[Functor[Int => ?]].map(_ + 2)(_.toString)
println(func(5))
But when I try
object Chapter1 extends App
import Functor.ops._
val x : Int => Int = _ + 2
val y : Int => String = x.map(_.toString)
It doesn't find my implicit implementation and says that the value map
is not a member of Int => Int
scala simulacrum
scala simulacrum
asked Mar 24 at 21:36


Knows Not MuchKnows Not Much
11.4k29112227
11.4k29112227
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Compiler can't see that Int => Int
is Int => ?
applied to Int
.
Add
scalacOptions += "-Ypartial-unification"
to build.sbt.
It's necessary for normal work with higher-kinded types with Cats, Scalaz or manually.
By the way, there's no sense to import Functor._
1
Ahhh.... This is the 100th time partial unification has bit me
– Knows Not Much
Mar 24 at 22:11
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328810%2fimplicit-for-function-not-being-found%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Compiler can't see that Int => Int
is Int => ?
applied to Int
.
Add
scalacOptions += "-Ypartial-unification"
to build.sbt.
It's necessary for normal work with higher-kinded types with Cats, Scalaz or manually.
By the way, there's no sense to import Functor._
1
Ahhh.... This is the 100th time partial unification has bit me
– Knows Not Much
Mar 24 at 22:11
add a comment |
Compiler can't see that Int => Int
is Int => ?
applied to Int
.
Add
scalacOptions += "-Ypartial-unification"
to build.sbt.
It's necessary for normal work with higher-kinded types with Cats, Scalaz or manually.
By the way, there's no sense to import Functor._
1
Ahhh.... This is the 100th time partial unification has bit me
– Knows Not Much
Mar 24 at 22:11
add a comment |
Compiler can't see that Int => Int
is Int => ?
applied to Int
.
Add
scalacOptions += "-Ypartial-unification"
to build.sbt.
It's necessary for normal work with higher-kinded types with Cats, Scalaz or manually.
By the way, there's no sense to import Functor._
Compiler can't see that Int => Int
is Int => ?
applied to Int
.
Add
scalacOptions += "-Ypartial-unification"
to build.sbt.
It's necessary for normal work with higher-kinded types with Cats, Scalaz or manually.
By the way, there's no sense to import Functor._
edited Mar 24 at 22:05
answered Mar 24 at 22:00
Dmytro MitinDmytro Mitin
12.1k1622
12.1k1622
1
Ahhh.... This is the 100th time partial unification has bit me
– Knows Not Much
Mar 24 at 22:11
add a comment |
1
Ahhh.... This is the 100th time partial unification has bit me
– Knows Not Much
Mar 24 at 22:11
1
1
Ahhh.... This is the 100th time partial unification has bit me
– Knows Not Much
Mar 24 at 22:11
Ahhh.... This is the 100th time partial unification has bit me
– Knows Not Much
Mar 24 at 22:11
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328810%2fimplicit-for-function-not-being-found%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown