Haskell中的单个实体如何重新出口

发布于 2025-02-09 20:24:26 字数 715 浏览 1 评论 0原文

如何在Haskell中重新出口单个实体?
我知道可以重新出口模块,但是单个实体(例如函数)也可以吗?

我尝试了这个示例:
文件:yomedata.hs

module SomeData where
data SomeData = SomeData

文件:reexport.hs

module ReExport ( SomeData ) where
import SomeData

file:main.hs

import ReExport

x = SomeData -- Error on this line: Illegal term-level use of the type constructor ‘SomeData’

单独的重新分组毫无问题,但是当我尝试尝试时要使用任何内容,我会得到错误:非法术语级别的使用构造函数'Someedata'。在这种情况下,Reexport.hs到底是什么?

How to re-export a single entity in haskell?
I know modules can be re-exported, but is this also possible for a single entity (like a function)?

I've tried this example:
File: SomeData.hs

module SomeData where
data SomeData = SomeData

File: ReExport.hs

module ReExport ( SomeData ) where
import SomeData

File: Main.hs

import ReExport

x = SomeData -- Error on this line: Illegal term-level use of the type constructor ‘SomeData’

The re-export alone compiles with no problems, but when I try to use anything from it I get the error: Illegal term-level use of the type constructor ‘SomeData’. What exactly is ReExport.hs exporting in this case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓦然回首 2025-02-16 20:24:27

在这种情况下,reexport.hs出口到底是什么?

type构造函数,因此您可以使用ymedata作为类型:

import ReExport

x :: SomeData
x = undefined

如果定义类型:

data SomeType = SomeData

因此,您正在导出worder stype

如果您也想导出数据构造函数,则可以使用:

module ReExport (SomeData(SomeData)) where

import SomeData

然后可以使用:

import ReExport

x :: SomeData
x = SomeData

What exactly is ReExport.hs exporting in this case?

The type constructor, so you can use SomeData as type:

import ReExport

x :: SomeData
x = undefined

If you defined a type:

data SomeType = SomeData

you are thus exporting SomeType.

If you want to export the data constructor as well, you use:

module ReExport (SomeData(SomeData)) where

import SomeData

and then you can thus use:

import ReExport

x :: SomeData
x = SomeData
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文