如何解决 Ocaml 类型错误?
How can I get arround Ocaml's type error?
我有这个警告,我想知道他为什么要等待 Unix.file_descr list * Unix.file_descr list * Unix.file_descr list
类型的表达式
这是函数,如果您需要更多代码,请问我。
let rec run()=
let a = create_bloc() in
trace_bloc(a);
let b : char ref = ref 'f' in
while true do
b := 'f';
if !(a.s) = 1 then run() else
let c = get_move() in
if c = Some 'z' then b:= 'z'
else if c = Some 'q' then b:= 'q'
else if c = Some 's' then b:= 's'
else if c = Some 'd' then b:= 'd';
if !b = 'z' || !b = 's' then
if !(a.o) = 4 && !b = 'z' then begin erase_bloc(a) ;a.o := 1; trace_bloc(a); end
else if !b = 'z' && !(a.o) <> 4 then begin erase_bloc(a); a.o := !(a.o)+1; end;
if !b = 's' && !(a.o)=1 then begin erase_bloc(a);a.o := 4;trace_bloc(a);end else
if !b = 's' && !(a.o) <> 1 then begin erase_bloc(a); a.o := !(a.o)-1;trace_bloc(a);end
else if !b = 'd' || !b = 'q' then
decal(a,!b);
dep_bas(a);
Unix.select [] [] [] 0.35;
done;
;;
Unix.file_descr list * Unix.file_descr list * Unix.file_descr list
类型是由表达式 Unix.select [] [] [] 0.35;
返回的值的类型
OCaml 不允许您忽略由 unit
以外类型的函数返回的值。但是,您可以使用 ignore
函数明确告诉编译器您不需要 select
函数的结果,
ignore (Unix.select [] [] [] 0.35);
您还可以使用Unix.sleepf
函数实现支持小数秒的休眠,例如,您可以将上面的表达式替换为just,
Unix.sleepf 0.35
这也会暂停您的程序 350 毫秒。
我有这个警告,我想知道他为什么要等待 Unix.file_descr list * Unix.file_descr list * Unix.file_descr list
这是函数,如果您需要更多代码,请问我。
let rec run()=
let a = create_bloc() in
trace_bloc(a);
let b : char ref = ref 'f' in
while true do
b := 'f';
if !(a.s) = 1 then run() else
let c = get_move() in
if c = Some 'z' then b:= 'z'
else if c = Some 'q' then b:= 'q'
else if c = Some 's' then b:= 's'
else if c = Some 'd' then b:= 'd';
if !b = 'z' || !b = 's' then
if !(a.o) = 4 && !b = 'z' then begin erase_bloc(a) ;a.o := 1; trace_bloc(a); end
else if !b = 'z' && !(a.o) <> 4 then begin erase_bloc(a); a.o := !(a.o)+1; end;
if !b = 's' && !(a.o)=1 then begin erase_bloc(a);a.o := 4;trace_bloc(a);end else
if !b = 's' && !(a.o) <> 1 then begin erase_bloc(a); a.o := !(a.o)-1;trace_bloc(a);end
else if !b = 'd' || !b = 'q' then
decal(a,!b);
dep_bas(a);
Unix.select [] [] [] 0.35;
done;
;;
Unix.file_descr list * Unix.file_descr list * Unix.file_descr list
类型是由表达式 Unix.select [] [] [] 0.35;
OCaml 不允许您忽略由 unit
以外类型的函数返回的值。但是,您可以使用 ignore
函数明确告诉编译器您不需要 select
函数的结果,
ignore (Unix.select [] [] [] 0.35);
您还可以使用Unix.sleepf
函数实现支持小数秒的休眠,例如,您可以将上面的表达式替换为just,
Unix.sleepf 0.35
这也会暂停您的程序 350 毫秒。