如何重新导出合格的导入模块? [英] How do I reexport qualified imported modules?

查看:143
本文介绍了如何重新导出合格的导入模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在haskell中重新导出合格的导入模块?有可能吗?

How can I reexport qualified imported modules in haskell? It is possible?

示例:我有两个文件。文件 Utils.hs 与代码:

Example: I have two files. The file Utils.hs with the code:

module Utils (...) where

import qualified Data.Map as Map

以及 main.hs

import Utils

main = putStrLn $ show $ Map.fromList [(1,2),(3,4)]

在文件 Utils.hs 中,我必须放置什么,而不是 ... ,以便上述文件编译并将 fromList [(1,2),(3,4)] 打印到标准输出?

What do I have to put instead of ... in the file Utils.hs so that the above file compiles and prints fromList [(1,2),(3,4)] to the standard output?

目标:通过导入Utils 在另一个文件中导入 Utils.hs 之后,我想要可以使用代码 Map。<函数或数据名称> 访问 Data.Map 的函数和类型,即写入 import Utils 我不需要将>导入限定的Data.Map作为Map 。这可能吗?

Goal: After importing Utils.hs in another file via import Utils I want to have access to the functions and types of Data.Map with the code Map.<function or data name>, i.e. so that with writing import Utils I do not have to write import qualified Data.Map as Map any more. Is this possible?

注意: Haskell重新导出模块以及模块中定义的所有内容。不幸的是,在这种情况下,答案没有帮助。

Note: There is a similar question at Haskell re-export module in addition to everything defined within module. Unfortunately the answer does not help in this situation.

我到目前为止所尝试的是:以下代码

What I tried so far: The following code

module Utils (module Map) where

import qualified Data.Map as Map

编译,但是我得到错误 main.hs:3:26:不在范围内:`Map.fromList'如果我尝试编译 main.hs

compiles, but I get the error main.hs:3:26: Not in scope: `Map.fromList' if I try to compile main.hs.

推荐答案

你所要求的是不可能的。 Map.fromList 只有在导入表单时才会成功解析

What you're asking for is not possible. Map.fromList will resolve successfully only if there's an import of the form

import [qualified] Map

import [qualified] ... as Map

这篇关于如何重新导出合格的导入模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆