如何导入 GHCi 路径中的模块?
How can I import a module that is in GHCi paths?
我直接执行ghci
时好像无法导入模块,但是在执行ghci xmonad.hs
时可以加载模块。
目录树:
.
├── ghcid.sh
├── lib
│ ├── FocusWindow.hs
│ ├── MiddleColumn.hs
│ ├── Readme.md
│ └── TAGS
├── Readme.md
├── TAGS
├── xmonad2.hs
├── xmonad.errors
├── xmonad.hs
├── xmonad.state
├── xmonad.state.backup
└── xmonad-x86_64-linux
.ghci
:set -Wall
:set -i:lib
ghci提示:
Prelude> :show paths
current working directory:
/home/chris/.xmonad
module import search paths:
.
lib
Display all 2040 possibilities? (y or n)
Prelude> import FocusWindow
<no location info>: error:
Could not find module ‘FocusWindow’
It is not a module in the current program, or in any known package.
ghci xmonad.hs提示
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/chris/.xmonad/.ghci
[1 of 3] Compiling FocusWindow ( lib/FocusWindow.hs, interpreted )
[2 of 3] Compiling MiddleColumn ( lib/MiddleColumn.hs, interpreted )
[3 of 3] Compiling Main ( xmonad.hs, interpreted )
Ok, modules loaded: MiddleColumn, FocusWindow, Main.
*Main> import FocusWindow
*Main FocusWindow> :show paths
current working directory:
/home/chris/.xmonad
module import search paths:
.
lib
您只能导入来自某个已知包或已加载的模块。当您 运行 ghci xmonad.hs
时,它会加载 xmonad.hs
及其所需的任何模块。当您 运行 ghci
时,它默认不加载任何内容。
您可以通过 运行ning :load FocusWindow
或简称 :l FocusWindow
单独加载您的模块。这也会以一种特殊的方式自动 "import" 该模块(具体来说:使所有名称可用,甚至是未导出的名称),并且您还可以正常导入 FocusWindow
使用的模块。
对于 ghci 的 import
支持来说,在抱怨之前尝试加载未知模块可能是一个不错的功能。我怀疑添加该功能的补丁会被接受。
我直接执行ghci
时好像无法导入模块,但是在执行ghci xmonad.hs
时可以加载模块。
目录树:
.
├── ghcid.sh
├── lib
│ ├── FocusWindow.hs
│ ├── MiddleColumn.hs
│ ├── Readme.md
│ └── TAGS
├── Readme.md
├── TAGS
├── xmonad2.hs
├── xmonad.errors
├── xmonad.hs
├── xmonad.state
├── xmonad.state.backup
└── xmonad-x86_64-linux
.ghci
:set -Wall
:set -i:lib
ghci提示:
Prelude> :show paths
current working directory:
/home/chris/.xmonad
module import search paths:
.
lib
Display all 2040 possibilities? (y or n)
Prelude> import FocusWindow
<no location info>: error:
Could not find module ‘FocusWindow’
It is not a module in the current program, or in any known package.
ghci xmonad.hs提示
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/chris/.xmonad/.ghci
[1 of 3] Compiling FocusWindow ( lib/FocusWindow.hs, interpreted )
[2 of 3] Compiling MiddleColumn ( lib/MiddleColumn.hs, interpreted )
[3 of 3] Compiling Main ( xmonad.hs, interpreted )
Ok, modules loaded: MiddleColumn, FocusWindow, Main.
*Main> import FocusWindow
*Main FocusWindow> :show paths
current working directory:
/home/chris/.xmonad
module import search paths:
.
lib
您只能导入来自某个已知包或已加载的模块。当您 运行 ghci xmonad.hs
时,它会加载 xmonad.hs
及其所需的任何模块。当您 运行 ghci
时,它默认不加载任何内容。
您可以通过 运行ning :load FocusWindow
或简称 :l FocusWindow
单独加载您的模块。这也会以一种特殊的方式自动 "import" 该模块(具体来说:使所有名称可用,甚至是未导出的名称),并且您还可以正常导入 FocusWindow
使用的模块。
对于 ghci 的 import
支持来说,在抱怨之前尝试加载未知模块可能是一个不错的功能。我怀疑添加该功能的补丁会被接受。