![](/img/trans.png)
[英]How can I represent an automaton graphically from a list of int*char*int representing the transitions without using loops
[英]how to draw an automaton diagram?
我根据许多人给我的建议使用graphviz
,但遇到了一个问题。 我想使用Format.module
在ocaml
写一个点,并且我有一条包含五个字段的记录,这些字段定义了一个自动机,其中包括由int*char*int
列表表示的转换和由int
列表表示的最终状态。 第一个字段是初始状态,为int
。 我还定义了一个函数成员,该成员接受一个参数并测试它是否是给定列表的成员。 我该怎么做才能写一个完整的点来识别初始状态,并用node [shape = point]start ; start -> x
表示它[shape = point]start ; start -> x
[shape = point]start ; start -> x
以及其他带有圆圈的过渡和带有双圆的最终状态? 我尝试这样做,但是编译时遇到了问题
文件“ automatagraphicstest1.ml”,第44行,字符22-37:错误:此表达式的类型为autoate-> Format.formatter-> int * char * int-> unit,但期望使用的表达式类型为Format.formatter->' ->单位类型自动与Format.formatter类型不兼容
要解决您的类型错误,只需将fmt_transitions
函数替换为此:
let fmt_transitions fmt auto =
Format.fprintf fmt "@[<v 2>digraph output {@,%a@,@]}@,@."
(Format.pp_print_list (fmt_transition1 auto)) auto.transitions
您的问题是pp_print_list
期望使用Format.formatter -> 'a -> unit
类型的东西。 您的函数fmt_automaton1
将自动机作为额外的第一个参数,因此我们需要首先部分应用它,然后才能提供转换列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.