英文:
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'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>
}
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
那么你将无法隐藏Client中P的定义(这可能是一个错误)。
英文:
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't want to reveal the implementation of P by default
  type P<!T(==)> = iset<T>
}
module B {
  export
    provides Test, JustP
  import JustP = A
  import opened Everything = A`all
  function Test(): P<nat> {
    iset{} // module B knows what P is, because it imports A`all
  }
}
module Client {
  import B
  method M() {
    var p: B.JustP.P<nat>; // 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<nat>
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).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论