2

ファンクタの結果から型を導出する構造で使用されるシグネチャで型を参照するにはどうすればよいですか。poly インタープリターを使用した例を次に示します。

> signature Res = sig type f end;
signature Res = sig type f end
> functor F (A: sig type t end) : Res = struct datatype f = None | Some end;
functor F (A: sig type t end): Res
> structure S = struct local structure A = F(struct type t = int end) in type t = A.f list end end;
structure S: sig type t = A.f list end

まず、Af が構造に対してローカルである場合に、結果の署名に Af が表示される理由がわかりません。次に、この構造 S に一致する署名を作成するにはどうすればよいですか?

このようなものは機能しません:

signature SSig = sig type t = F(struct type t = int end).t list end

また、型 f がデータ型ではなく int の場合、最終的に S は f が署名によって隠されているのではなく int であることを認識するようになります。不透明な署名を使用してもintが表示されない場合でも、これは合理的な動作とは思えません。

> functor F (A: sig type t end) : Res = struct type f = int end;
functor F (A: sig type t end): Res
> structure S = struct local structure A = F(struct type t = int end) in type t = A.f list end end;
structure S: sig type t = int list end
> functor F(A: sig type t end):> Res = struct type f = int end;
functor F (A: sig type t end): Res
> structure S = struct local structure A = F(struct type t = int end) in type t = A.f list end end;
structure S: sig type t = A.f list end
4

2 に答える 2

1

[...] Af が構造に対してローカルである場合に、結果の署名に Af が表示される理由。

これは、Poly/ML のアーティファクトのようです。Moscow MLは名前を漏らしていないようです:

Moscow ML version 2.10
Enter `quit();' to quit.
- signature Res = sig type f end;
> signature Res = /\f.{type f = f}
- functor F (A: sig type t end) : Res =
  struct
    datatype f = None | Some
  end;
> functor F : !t.{type t = t}->?=f.{type f = f}
- structure S =
  struct
    local structure A = F(struct type t = int end)
    in type t = A.f list
    end
  end;
> New type names: =f
  structure S : {type t = f list}

ファンクタの結果から型を導出する構造体で使用されるシグネチャで型を参照するにはどうすればよいですか?

(コメント)問題は、SSig で型を不透明にしたくないことですが、コンシューマーにアクセスさせたくないので、署名に R を含めたくありません。不透明な型 f = Rf で同様のことを行うことができますが、それを署名に含める必要があり、再び署名が乱雑になります。

モジュールを設計するときに、型レベルまたはモジュール レベルのどちらでパラメーター化するかを決定する方法に関する Drup による最近の回答では、モジュールの入力型を単形化することの欠点について説明しています。

すべての R に含まれる型が t である場合、「SSig で不透明にする」と「SSig の署名に R を含めない」ことは同等ではありませんか? Res には t 型よりも多くのものが含まれている可能性があります。その場合は、structure R : sig type t end代わりに指定できます。または、おそらく Ionuț の回答のこのバリエーションが望ましいです。

signature Res =
sig
  type t (* rather than structure R *)
  type f = t list
end

functor F (A : sig type t end) : Res =
struct
  type t = A.t
  type f = t list
end

structure S = F(struct type t = int end)

の重複を避ける方法がわかりませんtype f = t list

于 2016-09-27T14:29:28.077 に答える