簡體   English   中英

如何導入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 ,默認情況下它不會加載任何內容。

您可以通過運行:load FocusWindow:l FocusWindow:l FocusWindow來單獨加載模塊。 這也將自動以特殊方式“導入”該模塊(特別是:使所有名稱可用,甚至是未導出的名稱),並且您也將能夠正常導入FocusWindow使用的模塊。

ghci的import支持在抱怨之前嘗試加載未知模塊可能是一個不錯的功能。 我懷疑添加該功能的補丁會被接受。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM