ocaml - 如何解决 Ocaml 的类型错误?
问题描述
我有这个警告,我想知道他为什么要等待类型的表达式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 毫秒。
推荐阅读
- python - 我想将 python 输出列表转换为数组
- javascript - 在图像 HTML/Javascript 上书写
- java - 对象引用不影响它引用的对象?
- go - 使用 bufio.NewScanner 提高阅读性能
- python - 如何在 seaborn.lineplot 中将所有线条更改为黑色?
- javascript - 关于幻灯片。需要在列表中获取幻灯片的第一张图片
- r - Predict.glm 返回负概率?
- r - Tidymodels - Get predictions and metrics on training data using workflow/recipe
- python - 是否有任何 matplotlib 函数可以在图表中的两点之间创建增长箭头?
- javascript - 有没有办法在 JavaScript 中以指定的顺序从 n (n>1) RGBA 颜色计算混合颜色(以 RGB 为单位)?