1) I'm guessing the following should be a compile error, given that you cannot
return a by-name type:
abstract class Foo {
def identity[T](x : => T) : ( => T)
}
2) Its interesting that you can't write an identity function for a by-name
parameter, it gets evaluated immediately:
scala> def identity[T](x : T) = x
identity: [T](T)T
scala> identity { println("10") }
10
The only way I've found to not evaluate a by-name parameter seems to be to put
it in a Function0:
scala> def f(block : => Unit) = { () => { println("calling block"); block } }
f: (=> Unit)() => Unit
# Note that this println is not called here...
scala> val g = f { println("doing work") }
g: () => Unit = <function>
# ...but it is called here.
scala> g()
calling block
doing work
Blair
--
Blair Zajac, Ph.D.
CTO, OrcaWare Technologies
<
blair@...>
Subversion training, consulting and support
http://www.orcaware.com/svn/