4
import scalaz._; import Scalaz._
def foo[M[_]:MonadPlus,A](a:A) = a.point[M]
// foo: [M[_], A](a: A)(implicit evidence$1: scalaz.MonadPlus[M])M[A]
def bar1[M[_]:MonadPlus](i:Int): M[Int] =
foo(i) // <-- error: ambiguous implicit values
// this works, but why? Isn't it just the same?
def bar2[M[_]:MonadPlus](i:Int): M[Int] =
foo(i)(implicitly[MonadPlus[M]])
def bar3[M[_]](i:Int)(implicit m:MonadPlus[M]): M[Int] =
foo(i)(m) // slightly less surprising that this works
def bar4[M[_]:MonadPlus](i:Int): M[Int] =
foo[M,Int](i) // this also works, but why?
build.sbt :타입 파라미터 유추 + 고차 종류 + 형 클래스 = :-(
scalaVersion := "2.9.2"
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.0.0-M5"
(I는 2.10.0-RC3 동일한 결과를 얻을 수있다)
죄송합니다. 1 년 후 대답은 나에게 명백한 것처럼 보인다. 'bar1'은 어떤 종류의'MonadPlus'가'foo'에 전달 될지를 지정하지 않습니다; 'bar2','bar3','bar4'는 명시 적 인수 또는 형식 인수를 통해 수행됩니다. 솔직히 내가 뭘 생각하는지 모르겠다. – arya