Accumulator factory: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 1,043: | Line 1,043: | ||
|that are usually not nullable, such as int or real. |
|that are usually not nullable, such as int or real. |
||
|In the following code we are telling EMal that int and real implement |
|In the following code we are telling EMal that int and real implement |
||
|the Number virtual interface, so that it can only |
|the Number virtual interface, so that it can only |
||
|accept null (because it's an interface), int, and real values. |
|||
|^ |
|^ |
||
type Number |
type Number allows int, real |
||
type AccumulatorUsingNumber |
type AccumulatorUsingNumber |
||
fun foo = fun by Number n |
fun foo = fun by Number n |
||
Line 1,078: | Line 1,079: | ||
for int i = 0; i < 2; ++i |
for int i = 0; i < 2; ++i |
||
generic solution = solutions[i] |
generic solution = solutions[i] |
||
writeLine("=== solution |
writeLine("=== solution " + (i + 1) + " ===") |
||
fun x = :solution.foo(1) |
fun x = :solution.foo(1) |
||
x(5) |
x(5) |
||
Line 1,091: | Line 1,092: | ||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
=== solution |
=== solution 1 === |
||
Org:RosettaCode:Number, Real: <8.3> |
Org:RosettaCode:Number, Real: <8.3> |
||
Org:RosettaCode:Number, Integer: <8> |
Org:RosettaCode:Number, Integer: <8> |
||
=== solution |
=== solution 2 === |
||
Variable, Real: <8.3> |
Variable, Real: <8.3> |
||
Variable, Integer: <8> |
Variable, Integer: <8> |