7

HaskellからOCamlに切り替えていますが、問題が発生しています。たとえば、正規表現の型定義が必要です。私はそうします:

type re = EmptySet 
    | EmptyWord
    | Symb of char
    | Star of re
    | Conc of re list
    | Or of (RegExpSet.t * bool) ;;

Or内の要素はセット(RegExpSet)にあるので、次にそれを定義します(そしてマップ関数も):

module RegExpOrder : Set.OrderedType = 
    struct
      let compare = Pervasives.compare
      type t = re
    end 
module RegExpSet = Set.Make( RegExpOrder )      
module RegExpMap = Map.Make( RegExpOrder ) 

しかし、「ocaml [ファイル名]」を実行すると、次のようになります。

Error: Unbound module RegExpSet

「re」の定義の「Or」の行。

これらの定義を交換した場合、つまり、定義を再入力する前にモジュール定義を記述した場合、明らかに次のようになります。

Error: Unbound type constructor re

「typet=re」の行にあります。

どうすればこれを解決できますか?ありがとう!

4

1 に答える 1

9

再帰モジュールの使用を試みることができます。たとえば、次のようにコンパイルされます。

module rec M : 
sig type re = EmptySet
    | EmptyWord
    | Symb of char
    | Star of re
    | Conc of re list
    | Or of (RegExpSet.t * bool) 
end = 
struct
  type re = EmptySet 
    | EmptyWord
    | Symb of char
    | Star of re
    | Conc of re list
    | Or of (RegExpSet.t * bool) ;;
end

and RegExpOrder : Set.OrderedType = 
    struct
      let compare = Pervasives.compare
      type t = M.re
    end 
and RegExpSet : (Set.S with type elt = M.re) = Set.Make( RegExpOrder )
于 2011-12-18T15:18:26.873 に答える