scala> def foo(i: => Int) = println("Foo"); foo _foo: (i: => Int)Unitres0: => Int => Unit = <function1>scala> def bar(f: Int => Unit) = f(0)bar: (f: Int => Unit)Unitscala> bar(res0)<console>:11: error: type mismatch;found : => Int => Unitrequired: Int => Unitbar(res0)^
scala> implicit def unByNameA[A, B](f: (=> A) => B): A => B = a => f(a)unlazyA: [A, B](f: => A => B)A => Bscala> bar(res0)Foo
(implicitly[Semigroup[A]].append _).curried(a) <-: ab
{ case (a1, b) => (a |+| a1, b) }
Roland Kuhn
Typesafe – The software stack for applications that scale.
twitter: @rolandkuhn
(=>A) is a Function0[A], so why do you expect it to be a supertype of A?
On Apr 23, 2012, at 21:09 , Chris Marshall wrote:
... there seems no reason that, given I can pass an =>A to a method which expects an A, that I should [not] be able to pass (=>A) => B to a method expecting an A => BChris
def foo(a: A)
scala> def bar[A](a: A) = println("Bar")bar: [A](a: A)Unitscala> def foo[A](a: =>A) = bar(a)foo: [A](a: => A)Unit
...it "makes sense" for me that (in Scala), A and =>A are essentially equivalent from the perspective of types.