打开应用于参数的顶级模块
Opening the top-level module applied on arguments
我想将顶级 Agda 模块的定义和使用它的本地匿名模块放在同一个文件中。但是,顶层模块有参数,我想在第二个模块中实例化它。
所以基本上我想做这样的事情:
module MyModule (A : Set) where
foo : A -> A
foo x = x
module _ where
open import Data.Bool
open MyModule Bool
bar = foo true
但是,open MyModule Bool
行失败并显示“模块 MyModule
未参数化,但正在应用于参数”。
有没有办法做到这一点而无需:
将第二个模块放在单独的文件中
缩进 MyModule
的内容,例如
module _ where
module MyModule (A : Set) where
foo : A -> A
foo x = x
module _ where
open import Data.Bool
open MyModule Bool
bar = foo true
?
您要求的确切内容目前在 Agda 中是不可能的。我能想到的最接近的是:
module MyModule where
module Main (A : Set) where
foo : A -> A
foo x = x
private
module _ where
open import Data.Bool
open Main Bool
bar = foo true
open Main public
这将以通用形式公开主模块的内容,同时对其他模块隐藏私有定义 bar
。但是,当你引入模块并想要实例化参数时,你不能直接写open import MyModule Nat
,你必须写
import MyModule using (module Main)
open MyModule.Main Nat
(对于导入通用版本,open import MyModule
就可以了)。
我想将顶级 Agda 模块的定义和使用它的本地匿名模块放在同一个文件中。但是,顶层模块有参数,我想在第二个模块中实例化它。
所以基本上我想做这样的事情:
module MyModule (A : Set) where
foo : A -> A
foo x = x
module _ where
open import Data.Bool
open MyModule Bool
bar = foo true
但是,open MyModule Bool
行失败并显示“模块 MyModule
未参数化,但正在应用于参数”。
有没有办法做到这一点而无需:
将第二个模块放在单独的文件中
缩进
MyModule
的内容,例如module _ where module MyModule (A : Set) where foo : A -> A foo x = x module _ where open import Data.Bool open MyModule Bool bar = foo true
?
您要求的确切内容目前在 Agda 中是不可能的。我能想到的最接近的是:
module MyModule where
module Main (A : Set) where
foo : A -> A
foo x = x
private
module _ where
open import Data.Bool
open Main Bool
bar = foo true
open Main public
这将以通用形式公开主模块的内容,同时对其他模块隐藏私有定义 bar
。但是,当你引入模块并想要实例化参数时,你不能直接写open import MyModule Nat
,你必须写
import MyModule using (module Main)
open MyModule.Main Nat
(对于导入通用版本,open import MyModule
就可以了)。