Importing a number of modules at once - haskell

I have a number of modules under the same folder:
/src/Web/MyLib/Types/Entity1.hs
/src/Web/MyLib/Types/Entity2.hs
/src/Web/MyLib/Types/Entity3.hs
...
Most of them require importing the same modules such as Data.Time, UUID and others. Instead of importing those models to each of the modules under /src/Web/MyLib/Types/, is there any way to create one base module, say, /src/Web/MyLib/Types/Base.hs, import all those modules (Data.Time, UUID, ...) to it and then only import Base to EntityX? I've tried it and failed. Maybe I did something wrong.

Here's an example, taken from Control.Lens, which achieves what you want: it imports everything in a base module and re-exports everything.
module Control.Lens
( module Control.Lens.At
, module Control.Lens.Cons
, module Control.Lens.Each
-- ...
) where
import Control.Lens.At
import Control.Lens.Cons
import Control.Lens.Each
-- ...

Related

Import unqualified name in Node.js

In Python I can import the names in my module as qualified
import myModule
or unqualified
from myModule import *
In Node.js, I can import as qualified
var myModule = require('myModule')
Is there a way to import names unqualified?
You can do that in ES6: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
ES6 imports are not supported in node.js at this point though. You could get it by writing ES6 code and transpiling it with babel, for example https://babeljs.io/

Import modules in Haskell

For a Haskell project I've just started, I have two files Main.hs and Lib.hs
However, I often find myself reaching for some modules that I've imported inside Lib while working in Main.
Is there a way to automatically load in Main.hs all the modules already imported inside Lib?
Lib.hs
import System.Random
import Data.List
{-
Lib code here
-}
Main.hs
import Lib -- Importing should automatically imports System.Random and Data.List
main = undefined
Modules can export other modules, including themselves (meaning they export all top level definitions instead of an explicit list of symbols you'd otherwise need to rely on).
module Lib ( module System.Random, module Data.List, module Lib) where
import System.Random
import Data.List
{-
Lib code here
-}

import a whole module at one time with Haskell

I'm embarrassed with a library problem with Haskell.
I finished a library made of several files
src/MyLib/Firstbib.hs
src/MyLib/Secondbib.hs
...
src/MyLib/Lastbib.hs
At this time, After cabal install I can import each file separatly with
import MyLib.Firstbib
import MyLib.Secondbib
import MyLib.Lastbib
every thing is OK
Now, I would like to import all these part of MyLib in a simple import :
import MyLib
and I can't reach to make it.
I tried to create a file named src/MyLib.hs containing :
module MyLib where
import MyLib.Types
import MyLib.Functions
import MyLib.Algo.Line
import MyLib.Algo.Point
and expose it with Cabal
Library
-- Modules exported by the library.
Hs-Source-Dirs: src
Exposed-modules: MyLib
, MyLib.Functions
, MyLib.Types
, MyLib.Algo.Line
, MyLib.Algo.Point
but it doesn't work.!
What it the correct way to import many files with only one module import (as for Gtk2Hs for example)?
This is how MyLib should look like -- maybe with different indentation:
module MyLib
(module MyLib.Types
,module MyLib.Functions
,module MyLib.Algo.Line
,module MyLib.Algo.Point
) where
import MyLib.Types
import MyLib.Functions
import MyLib.Algo.Line
import MyLib.Algo.Point
What happens is that when you put a module like that in your export list, you export all the symbols that your module knows about it.
You could potentially scope what part of this module you export, for example:
module ExampleLib
(module Data.Maybe
) where
import Data.Maybe (fromJust)
The above will just re-export fromJust from Data.Maybe, not the whole Data.Maybe module.

Could not find module, it is a member of the hidden package haskell98

When I try to compile a simple source file with import IO or import Random, the build fails with an error message like this:
Could not find module 'IO'
It is a member of the hidden package 'haskell98-2.0.0.1'
Use -v to see a list of the files searched for
The module names changed at some point. You probably want import System.IO and import System.Random instead.
Here is the module hierarchy for the standard libraries in GHC 7.6.1.

haskell import problem

I have a module "Dictionary", declared in a file "Dictionary.hs".
in the same directory i have a file "Def.hs" which imports Dictionary
here's the error i get
... /edsl/Def.hs:4:7:
Could not find module `Dictionary':
locations searched:
Dictionary.hs
Dictionary.lhs
... /edsl/Dictionary.hs is there. it's permissions are such that it can be written to or read from by anyone.
i really have no idea why i can't import. i'm using ghc 6.12.1 on mac os x 10.5.8
edit
here's the relevant code
in Dictionary.hs
module Dictionary where
...
and in in Def.hs
module Def where
import Control.Exception
import Data.Dynamic
import Dictionary
...
am i just defining the module incorrectly? i want to export all symbols.
i just found the problem. i'm using komodo edit, and the command the i created to load a file into ghci doesn't change the working directory.
doh.

Resources