Jump to content

Accumulator factory: Difference between revisions

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

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.