如何引用从函子的结果派生类型的结构中使用的签名中的类型。下面是使用聚解释一个例子:引用涉及函子签名结果的类型
> 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