how to draw an automaton diagram?

痞子三分冷 提交于 2019-12-12 01:23:23

问题


I used graphviz based on the recommendation given to me by many people but I ran into a problem. I want to write a dot in ocaml using the Format.module and I have a record with five fields that define an automaton including the transitions which are represented by a list of int*char*int and final states which are represented by an int list. The first field is the initial state which is one int. I also defined a function member that takes a parameter and tests if it is a member of a given list. How can I do so that I can write a full dot that recognizes the initial state and represent it with node [shape = point]start ; start -> x and the other transitions with circles and the final states with doublecircles? I tried doing it but I ran into problems When I compile it, it says

File "automatagraphicstest1.ml", line 44, characters 22-37: Error: This expression has type automate -> Format.formatter -> int * char * int -> unit but an expression was expected of type Format.formatter -> 'a -> unit Type automate is not compatible with type Format.formatter


回答1:


To fix your type error, just replace the fmt_transitions function by this:

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

Your issue is that pp_print_list expects something of type Format.formatter -> 'a -> unit. Your function fmt_automaton1 takes the automaton as extra first argument, so we need to partially apply it first, then we can provide the list of transitions.



来源:https://stackoverflow.com/questions/41901071/how-to-draw-an-automaton-diagram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!