如何在从函子的结果派生类型的结构中使用的签名中引用类型。下面是一个使用 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 在结构本地时会出现在结果签名中。其次,如何创建与此结构 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