首页 > 解决方案 > 如何解决 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;
;;

标签: ocaml

解决方案


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 毫秒。


推荐阅读