อธิบาย implicit conversion
อธิบาย implicit conversion
===============
as is a define implicit conversion.
Based on Scala,
as is working like an implicit conversion
for a term e if e is not compatible with its expected type
@Implicit (precendence=100) class Convert {
static String asType (Integer int) {
}
}
return invoke(Pair#setFirst as m', new C(e*) as B, x* as B*) as B
Reduction Rules
R-CALLSITE:
callsite(m, E, C) = S
-------------------------------------------------------------
(new C(e*)).m(d*) -> new S(m).call(new C(e*), d*)
R-INVK-1:
mbody(m, C) = x*.e0
----------------------------------------------------------
(new C(e*)).m(d*) -> [new C(e*)/this, d*/x*]e0
R-INVK-2:
mbody(m, C) = x*.e0
------------------------------------------------------------------
invoke(m, new C(e*), d*) -> [new C(e*)/this, d*/x*]e0
R-CALLSITE:
callsite(m, E, C) = m'.c.x*.s0
--------------------------------------
(new C(e*)).m(d*) -> [m/m', new C(e*)/c, d*/x*]s0
mbody(m, C) = x*.e0
R-EXEC:
mbody(m, C) = x*.e0
-------------------------------------
invoke(m, new C(e*), d*) -> [d*/x*, new C(e*)/this]e0
===========================================
reduction rules may be applied at any point in an expression
so we need obvious congruence rules
S { Object call(c, e*) { return invoke(m, c, e*); } }
new Pair(new A(), new B()).setFst(new B())
-> [Pair#setFst/m, new Pair(new A(), new B())/c, new B()/e*] new S(m).call(c, e*)
new S(Pair#setFst).call(new Pair(new A(), new B()), new B())
-> [Pair#setFst/m, new Pair(new A(), new B())/c, new B()/e*] invoke(m, c, e*)
invoke(Pair#setFst, new Pair(new A(), new B()), new B())
-> [new B()/newfst, new Pair(new A(), new B())/this] new Pair(newfst, this.snd)
Reduction rules
// mbody(m, C) = x*.e0
callsite(m, E, C) = new S(m').call(e0, x*)
----------------------------------------------------
(new C(e*)).m(d*) -> [d*/x*, new C(e*)/e0, m/m']new S(m).call(e0, x*)
x*.e0 = m(x*) {return e0;}
mbody(m, C) = x*.e0
----------------------------------------------------
invoke(m, e, d*) -> [d*/x*, e/this]e0