Haskell : loading ALL files in current directory path

后端 未结 2 1806
执念已碎
执念已碎 2020-12-21 00:16

The command (in GHCi)

:load abc

Loads the functions in the file abc (which must exist in the current directory path). How would I load all

2条回答
  •  礼貌的吻别
    2020-12-21 00:35

    It's better if the filenames and the names of the modules will be the same:

    ➤ mv test1.hs NecessaryModule.hs
    ➤ ghci
    GHCi, version 7.0.4: http://www.haskell.org/ghc/  :? for help
    Loading package ghc-prim ... linking ... done.
    Loading package integer-gmp ... linking ... done.
    Loading package base ... linking ... done.
    Loading package ffi-1.0 ... linking ... done.
    Prelude> :load test
    [1 of 2] Compiling NecessaryModule  ( NecessaryModule.hs, interpreted )
    [2 of 2] Compiling Main             ( test.hs, interpreted )
    Ok, modules loaded: NecessaryModule, Main.
    

    since the :load command load module(s) (by filenames) and their dependents (as you can read by typing :help or :? in the GHCi prompt).

    Also the :load command erase all previous declarations which was defined in the current GHCi session, so for loading all files in the current directory you can do something like this:

    Prelude> :q
    Leaving GHCi.
    ➤ ghci *.hs
    GHCi, version 7.0.4: http://www.haskell.org/ghc/  :? for help
    Loading package ghc-prim ... linking ... done.
    Loading package integer-gmp ... linking ... done.
    Loading package base ... linking ... done.
    Loading package ffi-1.0 ... linking ... done.
    
    :
        module `main:NecessaryModule' is defined in multiple files: NecessaryModule.hs
                                                                test2.hs
    Failed, modules loaded: none.
    Prelude> :q
    Leaving GHCi.
    ➤ rm test2.hs
    ➤ ghci *.hs  
    GHCi, version 7.0.4: http://www.haskell.org/ghc/  :? for help
    Loading package ghc-prim ... linking ... done.
    Loading package integer-gmp ... linking ... done.
    Loading package base ... linking ... done.
    Loading package ffi-1.0 ... linking ... done.
    [1 of 2] Compiling NecessaryModule  ( NecessaryModule.hs, interpreted )
    [2 of 2] Compiling Main             ( test.hs, interpreted )
    Ok, modules loaded: NecessaryModule, Main.
    *NecessaryModule> 
    

提交回复
热议问题