从模块中导出类型运算符

Exporting type-operators from modules

如何导出类型运算符?考虑到它们可能与普通运算符发生冲突,如果可能的话,必须有一个特殊的语法。

我在 7.4.4 of the GHC User's Guide 部分找到了答案,其中指出:

There is now some potential ambiguity in import and export lists; for example if you write import M( (+) ) do you mean the function (+) or the type constructor (+)? The default is the former, but with -XExplicitNamespaces (which is implied by -XExplicitTypeOperators) GHC allows you to specify the latter by preceding it with the keyword type, thus:

import M( type (+) )

虽然看起来您实际上不需要指定 -XExplicitNamespaces,但也许 -XExplicitTypeOperators 是一个错字,本应是 -XTypeOperators。一些更多的经验证据:

★ → :set -XExplicitTypeOperators
Some flags have not been recognized: -XExplicitTypeOperators

您可能只想导出 类型运算符,而不是导入 类型。

我定义了 type a * b = ...,但是导出 (*) 导出了前奏函数 (*) 而不是类型同义词。与上面的答案类似,要 export 类型运算符,您可以使用语法:

module Foo (type (*)) where

  type a * b = ...