一連の関数とその型付け規則を表現したいと考えており、データ構造について考えています...たとえば、
For function "PLUS":
PLUS-integer: Integer -> Integer -> Integer, with priority high
PLUS-boolean: Boolean -> Boolean -> Integer, with priority high
...
For function "Unary Minus":
UM-0: Integer -> Integer, with priority high
UM-1: Date -> Date, with priority high
...
For function "Unary Minus":
UM-error: Date -> Error, with priority low
...
いくつかのコメント: 関数とルールの名前は常に一意です。1 つの関数 (例: PLUS) は常に一定数の引数を持ち、それに関連するいくつかの型付け規則を持つことができます。型付け規則には、1 つの名前 (例: PLUS-integer)、1 つの前提、1 つの結論、および 1 つの優先順位があります。同じ前提を共有するが、異なる結論を与える 2 つの型付け規則がある場合があります。この場合、違いを生むのは優先度です。
後で、次のような関数を定義する必要があります。
add_rule: add a rule to a function
get_rules: get all the rules from a function
get_first_rule: get the most priority rule from a function and a premise
get_conclusions: get all the conclusions that a function can give
get_errors: get all the rules whose conclusion is an error
get_function: get the function from a typing rule
set_priority: set a priority for a rule
...
この目的のために、これらの型を定義する従来の方法があるかどうかはわかりません...現時点では、次のような方法を想像しています。
type func =
{ name: string;
... }
type rule =
{ name: string;
premise: Type.t list;
conclusion: Type.t;
priority: Priority.t
... }
type rules = rule list
いくつかの質問:
1)配列と比較してrules
、のリストとして定義するのは良い考えですか...rule
func
2)との関係については、rules
いくつかのオプションがありrules
ますfunc
。func
のレコード フィールドとして作成しrule
ます。と のハッシュ テーブルを作成func
しrules
ます。func
からまでのマップを作成しrules
ます。どっちがいいのかさっぱりわからない…
考慮しなければならないもう 1 つの側面は、このデータベースのイニシエーションです。入力する項目がたくさんあるので、選択したタイプによって、イニシエーションが簡単に入力でき、簡単に見えるようになることを願っています...
誰でも助けてもらえますか?