如何导出在Dafny中打开的模块的成员?

huangapple go评论76阅读模式
英文:

How to export members of opened module in Dafny?

问题

I can't get the following example to pass resolution in Dafny:

  1. module A {
  2. export all reveals *
  3. export provides P // I don't want to reveal the implementation of P by default
  4. type P<!T(==)> = iset<T>;
  5. }
  6. module B {
  7. import opened A`all
  8. export provides Test
  9. function Test(): P<nat>
  10. }

基本上,我想要函数 Test() 默认从 B 提供,类型 P 也提供,而不是被显式地暴露出来。
我找不到在文档中如何实现这一目标。

英文:

I can't get the following example to pass resolution in Dafny:

  1. module A{
  2. export all reveals *
  3. export provides P // I don&#39;t want to reveal the implementation of P by default
  4. type P&lt;!T(==)&gt; = iset&lt;T&gt;
  5. }
  6. module B{
  7. import opened A`all
  8. export provides Test
  9. function Test(): P&lt;nat&gt;
  10. }

Basically, I would like the function Test() to be provided by default from B and the type P to also be provided, not revealed.
I can't find in the documentation how to achieve that.

答案1

得分: 1

你需要在B的导出设置中添加更多内容。以下是一种方法:

  1. module A {
  2. export all
  3. reveals *
  4. export
  5. provides P // 默认情况下,我不想透露P的实现
  6. type P<!T(==)> = iset<T>
  7. }
  8. module B {
  9. export
  10. provides Test, JustP
  11. import JustP = A
  12. import Everything = A`all
  13. function Test(): P<nat> {
  14. iset{} // 模块B知道P是什么,因为它导入了A`all
  15. }
  16. }
  17. module Client {
  18. import B
  19. method M() {
  20. var p: B.JustP.P<nat>; // 客户端可以使用P,但只能作为不透明类型
  21. p := iset{}; // 错误:客户端不知道P是什么
  22. }
  23. }

你还可以将

  1. import opened Everything = A`all

更改为

  1. import Everything = A`all

如果你同时更改B.Test的签名为

  1. function Test(): Everything.P<nat>

但是由于某种原因,如果你将"everything"导入声明更改为

  1. import opened A`all

那么你将无法隐藏ClientP的定义(这可能是一个错误)。

英文:

You need to say more in the export set of B. Here's a way you can do it:

  1. module A{
  2. export all
  3. reveals *
  4. export
  5. provides P // I don&#39;t want to reveal the implementation of P by default
  6. type P&lt;!T(==)&gt; = iset&lt;T&gt;
  7. }
  8. module B {
  9. export
  10. provides Test, JustP
  11. import JustP = A
  12. import opened Everything = A`all
  13. function Test(): P&lt;nat&gt; {
  14. iset{} // module B knows what P is, because it imports A`all
  15. }
  16. }
  17. module Client {
  18. import B
  19. method M() {
  20. var p: B.JustP.P&lt;nat&gt;; // Client can use P, but only as an opaque type
  21. p := iset{}; // error: Client does not know what P is
  22. }
  23. }

You can also change

  1. import opened Everything = A`all

to just

  1. import Everything = A`all

if you also change the signature of B.Test to

  1. function Test(): Everything.P&lt;nat&gt;

But, for reasons I don't understand, if you change the "everything" import declaration to

  1. import opened A`all

then you don't get the desired effect of hiding the definition of P from Client (this may be a bug).

huangapple
  • 本文由 发表于 2023年3月31日 23:59:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75900562.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定