SML 中的函子结构扩展和多重归属
标准机器学习中是否有任何方法可以使函子输出一个结构,该结构具有传入结构的所有功能以及任何新功能。
同理,是否可以进行多重归属?在上述情况下,它会立即有用,因为您可以将仿函数的输出归因于原始结构的签名和指定新功能的另一个签名。
我理解做这样的事情的含义,以及为什么这可能是一个坏主意。目前,我只是在函子输出中保留传入结构的副本 - 但这意味着您有一个长链“Foo.Bar.func”来访问基本功能。
谢谢
Is there any way in Standard ML to make a functor output a structure which has all of the functionality of the passed in structure, plus any new functionality.
In a similar way, is it possible to do multiple ascription? In the case of the above it would be immediately useful because you could ascribe the output of the functor to both the signature of the original structure and another signature which specifies the new functionality.
I understand the implications of doing such a thing, and why it might be a bad idea. Currently I've just been keeping a copy of the passed in structure within the functor output - but this means you have a long chain of "Foo.Bar.func" to access the base functionality.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解您的问题,那么您正在寻找
include
关键字,该关键字会将先前签名的定义包含到新签名中,从而使用先前的定义扩展签名。If I understand your question correctly then you are looking for the
include
keyword, which will include the definition of a previous signature into a new and thus extending the signature with the previous definitions.您可以使用
open
将结构的内容放入当前范围。如果在另一个结构(或函子)中使用,它会做我相信你想要的事情。可以在这里看到一个例子:
You can use
open
to bring the contents of a structure into the current scope. If used inside another structure (or functor), it'll do what I believe it is you want.An example can be seen here: