Haskell 在一个文件中导出多个模块

Haskell 在一个文件中导出多个模块,haskell,import,module,Haskell,Import,Module,我需要在一个Haskell文件中导出两个模块。现在,我有 module name (important,functions) where module nameForTesting where -- the code is here 但是,它给了我这个错误: filename.hs:5:1: error: parse error on input ‘module’ 如何解决此问题?您需要区分定义模块和从该模块导出名称;这是两个独立的步骤 一个文件只能定义一个模块。但是,您可以将从其他模块导

我需要在一个Haskell文件中导出两个模块。现在,我有

module name (important,functions) where
module nameForTesting where

-- the code is here
但是,它给了我这个错误:

filename.hs:5:1: error: parse error on input ‘module’

如何解决此问题?

您需要区分定义模块和从该模块导出名称;这是两个独立的步骤

一个文件只能定义一个模块。但是,您可以将从其他模块导入的名称作为该模块的一部分导出。比如说,

module MyModule (foo, bar) where

import OtherModule (bar) -- Let's say bar :: Int -> String

foo :: Int -> Int
foo x = x + 3
MyModule
未定义
bar
;相反,它从
OtherModule
导入它,然后将其作为自身的一部分导出。
MyModule
的用户可以访问
bar
,而无需显式导入
OtherModule

import MyModule

main = putStrLn (bar (foo 9))

据我所知,同一个文件中不能有多个模块。似乎证实了这一点

但是,您可以创建第二个模块,用于重新导出某些函数。因此,我们首先创建一个文件
NameForTesting.hs
,其中包含:

-- NameForTesting.hs
module NameForTesting where

important :: Int
important = 42

functions :: Int -> Int
functions = (42 +)

foo :: Int
foo = 21
然后,我们可以构造第二个文件
Name.hs
,该文件导入
Name用于测试
模块,但仅导出
重要
函数

-- Name.hs
module Name(important, functions) where

import NameForTesting
--Name.hs
模块名称(重要,功能),其中
导入名称进行测试

名称
模块在此仅导出从
名称测试
模块导入的
重要
功能

文件属于一个模块。但是,您可以重新导入模块并导出子集。我不确定我是否理解。你能解释一下你的意思吗?