Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reexport qualified imported modules?

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

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

module Utils (...) where

import qualified Data.Map as Map

and the file main.hs:

import Utils

main = putStrLn $ show $ Map.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?

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?

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

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

like image 980
Stephan Kulla Avatar asked Apr 09 '14 20:04

Stephan Kulla


1 Answers

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

or

import [qualified] ... as Map
like image 103
Roman Cheplyaka Avatar answered Oct 18 '22 17:10

Roman Cheplyaka