Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell : can only load one file at a time via :load

suppose I have two modules NecessaryModule1 & NecessaryModule2 (as outlined in the post Haskell : loading ALL files in current directory path. Then I have noticed in both WinGHCi and GHCi that if I do :

> :load NecessaryModule1
[1 of 1] Compiling NecessaryModule1 ( NecessaryModule1.hs, interpreted )
Ok, modules loaded: NecessaryModule1.
> addNumber1 2 3
5
> :load NecessaryModule2
[1 of 1] Compiling NecessaryModule2 ( NecessaryModule2.hs, interpreted )
Ok, modules loaded: NecessaryModule2.
> addNumber1 2 3

<interactive>:1:1: Not in scope: `addNumber1'

i.e. loading NecessaryModule2 eliminates all the functions from NecessaryModule1.

So does that mean that the only way I can simultaneously load NecessaryModule1 & NecessaryModule2 is to use a third file (which imports both NecessaryModule1 & NecessaryModule2) and then load that third file? (e.g. see test.hs in Haskell : loading ALL files in current directory path) Thanks.

---------------------------------------------------------------------------------------

[RESPONSE TO geekosaur]

Hi, so if I have done :load NecessaryModule1 and then I want to load the module in MyMod.hs :

--MyMod.hs
module MyMod where
import Data.List

f x = sort x

then how would I do this? In Haskell : unload module in WinGHCi Riccardo explains that :module assumes that the modules have already been loaded. So does this mean that the only way to achieve the loading of multiple custom modules is to load them with a single call of the :load function? Thanks.

like image 222
artella Avatar asked Apr 25 '12 06:04

artella


2 Answers

Ok, there are two things to consider : what ":module" know to find, and what is actually in context at a given prompt.

:module always know how to find modules in installed packages (that are not hidden) and by default that's all that it has access to. But you can use :load to make it aware of some other modules in specific files. Each call of :load reset the set of additional modules (and :reload keep the same set of loaded module but refresh their content). Also :load put you into the context of the first module you specify.

In other word, if you want to get into a context where both modules are imported, you need to do :

> :load Module1 Module2
> :module Module1 Module2

So does this mean that the only way to achieve the loading of multiple custom modules is to load them with a single call of the :load function?

In other words : yes ! (but that doesn't seem to be a problem except that you need to repeat modules you loaded in the past if you still want to use them in the new context)

like image 70
Jedai Avatar answered Sep 28 '22 16:09

Jedai


:load loads your main program module. :module can be used to load additional modules:

> :load BaseModule -- this is the one that contains 'main'
> :module +AddedModule -- this is an additional library module

You can also use :module to unload these additional modules:

> :module -AddedModule -- after this @AddedModule@ will no longer be loaded

If you don't have a module with a main, you may want to use :module + to load all of your library modules.

like image 23
geekosaur Avatar answered Sep 28 '22 17:09

geekosaur