Functional programming 如何在函数编程中更正此错误?

Functional programming 如何在函数编程中更正此错误?,functional-programming,ocaml,graphviz,dot,automata,Functional Programming,Ocaml,Graphviz,Dot,Automata,在第44行,它给了我一个类型错误类型automate与类型格式化程序不兼容我正在尝试使用graphviz 代码如下: (*d'abord definissons le type automate*) type automate = { etat_initial : int; ensemble_des_etats : int list; alphabets : char list; transitions :(int*char*int) list; etats_finaux : int list

在第44行,它给了我一个类型错误类型automate与类型
格式化程序不兼容
我正在尝试使用
graphviz
代码如下:

(*d'abord definissons le type automate*)

type automate = {
etat_initial : int;
ensemble_des_etats : int list;
alphabets : char list;
transitions :(int*char*int) list;
etats_finaux : int list
};;

(*prenons une variable a1 du type automate qu'on a definit precedemment 
  comme 
  exemple*)

let a1={
etat_initial=1;
ensemble_des_etats=[1;2];
alphabets=['a';'b'];
transitions=[(1,'b',2);(2,'c',3)];
etats_finaux=[2]
};;

let rec member a l =
match l with
| [] -> false
| x::rl -> x=a || member a rl;;


let fmt_transition auto fmt (inedge,by,outedge)=
if member outedge auto.etats_finaux=true then
 Format.fprintf fmt "@[node [shape = doublecircle]%d;@]" outedge;
 if inedge=auto.etat_initial then
 Format.fprintf fmt "@[node [shape = point]start;node [shape = circle];start 
 -> %d ;@]" inedge;
 Format.fprintf fmt "@[%d -> %d [label=\"%c\"];@]" inedge outedge by;;

let fmt_transitions auto fmt =
Format.fprintf fmt "@[<v 2>digraph output {@,%a@,@]}@,@."
(Format.pp_print_list (fmt_transition auto)) auto.transitions
;;

 let call_dot auto =
 let cmd = "dot -Tpng | display -" in
 let (sout, sin, serr) as channels =
 Unix.open_process_full cmd (Unix.environment ()) in
 let fmt = Format.formatter_of_out_channel sin in
 <b>Format.fprintf fmt "%a@." fmt_transitions auto;</b>
 channels

let cleanup channels =
(* missing: flush channels, empty buffers *)
 Unix.close_process_full channels;;

call_dot a1 ;;
(*d'abord definissons le type automation*)
类型={
etat_首字母:int;
集合:整数列表;
字母表:字符列表;
转换:(int*char*int)列表;
最终结果:整数列表
};;
(*prenons une变量a1 du类型在定义的前提下自动执行
通信
例*)
让a1={
etat_初始值=1;
合奏曲=[1;2];
字母表=['a';'b'];
转换=[(1,'b',2);(2,'c',3)];
最终结果=[2]
};;
让rec成员a l=
匹配
|[]->false
|x::rl->x=a | |成员a rl;;
让fmt_转换为自动fmt(inedge、by、outedge)=
如果成员outedge auto.etats_finaux=true,则
Format.fprintf fmt“@[node[shape=doublecircle]%d;@]”outedge;
如果inedge=auto.etat_首字母,则
Format.fprintf fmt“@[node[shape=point]开始;node[shape=circle];开始
->%d;@]“边缘;
Format.fprintf fmt“@[%d->%d[label=\%c\”];@]”在边缘路由中;;
让fmt_转换自动fmt=
Format.fprintf fmt“@[有向图输出{@,%a@,@]}@。”
(Format.pp_print_list(fmt_transition auto))auto.transitions
;;
让我们叫点自动=
让cmd=“dot-Tpng | display-”进入
让(sout,sin,serr)作为通道=
中的Unix.open\进程\完整cmd(Unix.environment())
设fmt=Format.formatter\u of_out\u channel sin in
Format.fprintf fmt“%a@.“fmt_自动转换;
渠道
让清理通道=
(*缺少:刷新通道、空缓冲区*)
Unix.close_进程_完整通道;;
叫_dot a1;;

使用
%a
时需要小心。 根据OCaml文档:

a:用户定义的打印机。取两个参数,将第一个参数应用于outchan(当前输出通道)和第二个参数。 因此,第一个参数必须具有type out\u channel->'b->unit

fmt\u transitions auto fmt
函数的第一个参数必须是格式化程序,因此只需切换
auto
fmt
参数,就可以了

let fmt_transitions auto fmt = ...

let fmt_transitions fmt auto = ...

也涉及到了问题和问题。