2017-01-27 86 views
0

我使用graphviz根據很多人給我的建議,但我遇到了一個問題。我想使用Format.moduleocaml中寫一個點,並且我有一個記錄,其中有五個字段定義了一個自動機,其中包括由列表int*char*int表示的轉換以及由int列表表示的最終狀態。第一個字段是一個int的初始狀態。我還定義了一個函數成員,它接受一個參數並測試它是否是給定列表的成員。我該怎麼做,以便我可以編寫一個完整的點來識別初始狀態,並用節點[shape = point]start ; start -> x來表示它,並用圓圈表示最終狀態,用雙環來表示它們。我想這樣做,但我遇到了問題,當我編譯它,它說如何繪製一個自動機圖?

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

+0

請爲您的代碼使用pastebin。編輯器的屏幕截圖不可用。 – Drup

+0

http://pastebin.com/QK5qxEhd –

+0

http://pastebin.com/5NSb7qFU這是另一個嘗試我想要什麼,如果你看看它,你可能明白我想在這裏做什麼 –

回答

0

要解決你的類型的錯誤,只是這種替換fmt_transitions功能:

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

你的問題是pp_print_list預期類型爲Format.formatter -> 'a -> unit。您的函數fmt_automaton1將自動機作爲額外的第一個參數,所以我們需要先部分應用它,然後我們才能提供轉換列表。

+0

我明白了,但我需要測試一個inedge是否是我們在記錄中的int作爲初始狀態:etat_initial然後我們必須做node [shape = point] start;開始 - > inedge;並且如果outedge如果屬於列表etats_finaux則是最終狀態,那麼它應該是節點[shape = doublecircle] outedge; [shape = circle]; inedge-> outedge [label ='by']; –

+0

和形狀的圓到所有常規的轉換,但問題出在fmt –

+0

fmt_transitions *它只需要一個列表,我不知道用什麼來逃避字符串 –