11

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.

Community
  • 1
  • 1
Stephan Kulla
  • 4,739
  • 3
  • 26
  • 35
  • 2
    Export qualified modules is impossible: http://stackoverflow.com/questions/3207647/ghc-refuses-to-export-qualified-modules – user2407038 Apr 09 '14 at 20:42
  • @user2407038: Thanks for the link. Unfortunately I could not find the solution (see my extended question). Can you provide a running example? – Stephan Kulla Apr 09 '14 at 21:02

1 Answers1

10

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
Roman Cheplyaka
  • 37,738
  • 7
  • 72
  • 121