问题
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