如何在 haskell 中重新导出单个实体?
我知道模块可以重新导出,但这对于单个实体(如函数)也可能吗?
我尝试过这个例子:
文件:SomeData.hs
module SomeData where
data SomeData = SomeData
文件:ReExport.hs
module ReExport ( SomeData ) where
import SomeData
文件:Main.hs
import ReExport
x = SomeData -- Error on this line: Illegal term-level use of the type constructor ‘SomeData’
单独重新导出编译没有问题,但是当我尝试使用其中的任何内容时,我收到错误:非法术语级别使用类型构造函数“SomeData”。在这种情况下,ReExport.hs
到底导出什么?
最佳答案
What exactly is ReExport.hs exporting in this case?
类型构造函数,因此您可以使用 SomeData
作为类型:
import ReExport
x :: <strong>SomeData</strong>
x = undefined
如果您定义了类型:
data <strong>SomeType</strong> = <strong>SomeData</strong>
您因此导出SomeType
。
如果您还想导出数据构造函数,请使用:
module ReExport (SomeData<strong>(SomeData)</strong>) where
import SomeData
然后你可以使用:
import ReExport
x :: <strong>SomeData</strong>
x = <b>SomeData</b>
关于haskell - 如何在haskell中重新导出单个实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72722992/