This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Making reference to methods or object attribute.

No replies
Emmanuel Castro
Joined: 2012-01-25,
User offline. Last seen 42 years 45 weeks ago.

Dear all,

I am looking for a mean to express something that looks like a
closure: a reference to a method or an attribute.
I know that I can express it with a closure like that:
val myRef : MyObject => MyValue = _.myMethod

My problem is that I need a mean to compare such references, which is
AFAIK not possible with standard closure.

I would like something such as:
val myRef1 : String => Int = _.length
val myRef2 : String => Int = _.length
assert(myRef1 == myRef2) // actually throw assertion error

"Thanks to Turing", comparing closure is not possible in the general
case. What I need is a way to compare trivial closures. My criteria
for triviality is when I can call them method reference (or attribute
reference).

Any clue?

Thank you

Emmanuel

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland