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

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

How to export members of opened module in Dafny?

问题

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

module A {
  export all reveals *
  export provides P // I don't want to reveal the implementation of P by default
  type P<!T(==)> = iset<T>;
}

module B {
  import opened A`all
  export provides Test

  function Test(): P<nat>
}

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

英文:

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

module A{
  export all reveals *
  export provides P // I don&#39;t want to reveal the implementation of P by default
  type P&lt;!T(==)&gt; = iset&lt;T&gt;
}

module B{
  import opened A`all
  export provides Test

  function Test(): P&lt;nat&gt;
}

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的导出设置中添加更多内容。以下是一种方法:

module A {
  export all
    reveals *
  export
    provides P // 默认情况下,我不想透露P的实现

  type P<!T(==)> = iset<T>
}

module B {
  export
    provides Test, JustP

  import JustP = A
  import Everything = A`all

  function Test(): P<nat> {
    iset{} // 模块B知道P是什么,因为它导入了A`all
  }
}

module Client {
  import B

  method M() {
    var p: B.JustP.P<nat>; // 客户端可以使用P,但只能作为不透明类型
    p := iset{}; // 错误:客户端不知道P是什么
  }
}

你还可以将

  import opened Everything = A`all

更改为

  import Everything = A`all

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

function Test(): Everything.P<nat>

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

  import opened A`all

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

英文:

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

module A{
  export all
    reveals *
  export
    provides P // I don&#39;t want to reveal the implementation of P by default

  type P&lt;!T(==)&gt; = iset&lt;T&gt;
}

module B {
  export
    provides Test, JustP

  import JustP = A
  import opened Everything = A`all

  function Test(): P&lt;nat&gt; {
    iset{} // module B knows what P is, because it imports A`all
  }
}

module Client {
  import B

  method M() {
    var p: B.JustP.P&lt;nat&gt;; // Client can use P, but only as an opaque type
    p := iset{}; // error: Client does not know what P is
  }
}

You can also change

  import opened Everything = A`all

to just

  import Everything = A`all

if you also change the signature of B.Test to

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

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

  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:

确定