fun f(x : int) {
var y : int = 42;
y := y + 1;
return (x+y);
}
let comp main = read >>> map f >>> write
The second line is missing a colon and should be
var y : int := 42;
The "Just return a value" code:
fun comp f(x : int) {
var y : int := 0;
{ a <- { do { y := y + x; }
; z <- take
; emit (z+y);
; return y
}
; emit a
}
} ...
has an extra semi-colon, i.e.
; emit(z+y);
should just be ; emit(z+y)
The if statement does not run as described:
fun comp f() {
{ x <- take
; if (x > 0) then
emit (x+1)
else return ()
}
}
let comp main = read >>> f() >>> write
This takes only the first element and applies the if statement to it.
It says in the description that:
"The effect of this computer is that it will keep on incrementing all positive values of the input stream and emitting those to the output stream. However, once it meets the first non-positive one the whole computation will stop."
Finally, the for loop code:
fun comp f() {
for n in [0:4]
{ x <- take; emit x }
}
fun comp g(y : inr) }
for n in [0,y]
emit n -- n is bound in the body
}
let comp main = read >>> { f() ; g(100) } >>> write
should be
fun comp f() {
for n in [0:4]
{ x <- take; emit x }
}
fun comp g(y : int) {
for n in [0,y]
emit n -- n is bound in the body
}
let comp main = read >>> { f() ; g(100) } >>> write
(Where I have replaced g(y: inr) } with g(y:int) {)
In the first example of a map:
The second line is missing a colon and should be
The "Just
return
a value" code:has an extra semi-colon, i.e.
; emit(z+y);
should just be; emit(z+y)
The
if
statement does not run as described:This takes only the first element and applies the
if
statement to it. It says in the description that: "The effect of this computer is that it will keep on incrementing all positive values of the input stream and emitting those to the output stream. However, once it meets the first non-positive one the whole computation will stop."Finally, the
for
loop code:should be
(Where I have replaced
g(y: inr) }
withg(y:int) {
)