2017-02-09 9 views
1

それはタイプエラータイプの自動化は、ここでgraphviz を使用して、オートマトンを描画しようとしているタイプformatterイムと互換性がありません、私を与えるコードです:あなたは%aを使用するときは注意する必要がありますfunctionnalプログラミングでこのエラーを修正するにはどうすればよいですか?第44行に

(*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 {@,%[email protected],@]}@,@." 
(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 "%[email protected]" fmt_transitions auto;</b> 
channels 

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

call_dot a1 ;; 
+0

[どのようにループを使用せずに遷移を表すint *のchar * intのリストからグラフィカルオートマトンを表現することができます](http://stackoverflow.com/questions/41780982/how-オートマトン表現 - intcharint-represeからのグラフィカル表現)と[オートマトン図を描く方法](http://stackoverflow.com/questions/41901071/how-to -draw-an-automaton-diagram)である。 –

答えて

1

。 OCamlの文書によると:

a:ユーザ定義のプリンタ。 2つの引数をとり、最初のものをoutchan(現在の出力チャネル)と2番目の引数に適用します。 >「B - - 最初の引数は、したがってタイプout_channel持っている必要があります>ユニット ...

をごfmt_transitions auto fmt関数の最初の引数引数は、これだけautofmt引数を切り替えると、フォーマッタである必要がありますそれはOKであるはずです。また、質問に関連

let fmt_transitions auto fmt = ... 

let fmt_transitions fmt auto = ... 
+0

おかげで多くの仲間! –

関連する問題