如何引用從函子的結果派生類型的結構中使用的簽名中的類型。下面是使用聚解釋一個例子:引用涉及函子簽名結果的類型
> 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
首先,我不明白爲什麼A.f顯示了在得到的簽名時,它是局部的結構。其次,我如何創建一個符合這個結構S的簽名?
像這樣的東西不起作用:
signature SSig = sig type t = F(struct type t = int end).t list end
而且,如果F型是int,而不是數據類型,不知何故Ş最終意識到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
我擔心我可能不得不這樣做。問題是我不希望在SSig中使類型t不透明,但是我也不想讓R包含在簽名中,因爲我不希望消費者訪問它。我可以用一個不透明類型f = R.f來做類似的事情,但是我必須將其包含在簽名中,並且再次使簽名變得混亂。最後,我很困惑,因爲Res沒有給出f的類型定義。但我猜想因爲F不使用不透明簽名,SML可以將其用於S中。 – eatonphil