haskell - 如何在haskell中重新导出单个实体

标签 haskell module

如何在 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/

相关文章:

haskell - 为长度索引列表实现 zipper

haskell - 变量列表理解长度

haskell - 门德勒的组织形态论

javascript - node.js 本地模块 :cannot find module error

node.js - 将 angular2 模块/组件发布为 npm 包

swift - 如何在 Swift 中创建可导入模块?

Python 3 和 Excel,查找要使用的复杂模块

haskell - 在 Haskell 中从文件读取到数组

ruby-on-rails - Ruby 模块中常量的作用域

Haskell:可能的解决方法:将 (Eq a) 添加到