Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force accessing of a def

Considering

object A {
  def m(i: Int) = i
  val m = (i: Int) => i * 2
}

one gets

scala> A.m(2)
<console>: error: ambiguous reference to overloaded definition,
both value m in object A of type => (Int) => Int
and  method m in object A of type (i: Int)Int
match argument types (Int)
       A.m(2)
         ^

Accessing the val can be done with

scala> val fun = A.m
fun: (Int) => Int = <function1>

scala> fun(2)
res: Int = 4

or

scala> A.m.apply(2)
res: Int = 4

but how would one access the def?

like image 705
Debilski Avatar asked Sep 30 '11 10:09

Debilski


People also ask

What are forces def?

In Physics, force is defined as: The push or pull on an object with mass causes it to change its velocity. Force is an external agent capable of changing a body's state of rest or motion. It has a magnitude and a direction.

What does it mean when someone forces you to do something?

transitive verb. If someone forces you to do something, they make you do it even though you do not want to, for example, by threatening you.

What are the 3 formulas for force?

Therefore, F= m * a, F = ^P/^t, and F = ^(mV)/^t are formulae for force from Newton's first and second laws.

What are the four main types of forces?

fundamental force, also called fundamental interaction, in physics, any of the four basic forces—gravitational, electromagnetic, strong, and weak—that govern how objects or particles interact and how certain particles decay. All the known forces of nature can be traced to these fundamental forces.


1 Answers

It is total rubbish (please, don't do this at home), but you can do it by assigning A to a variable of structural type, that has only the first m.

val x : { def m(i:Int):Int } = A
x.m(10)
like image 163
jpalecek Avatar answered Oct 04 '22 14:10

jpalecek