简体   繁体   English

添加依赖项后如何重新加载项目?

[英]How to reload the project after dependencies is added?

During the development, I've added a library to package.yaml and the GHCi is already started. 在开发过程中,我已经向package.yaml添加了一个库,并且GHCi已经启动。

For example, I've added the bytestring library: 例如,我添加了bytestring库:

executables:
  playground-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - playground
    - text
    - bytestring

Because I use it in a file that is called Families.hs and it contains the following code: 因为我在名为Families.hs的文件中使用它,所以它包含以下代码:

{-# LANGUAGE  TypeFamilies, OverloadedStrings #-}

module Families where

import Data.Word (Word8)
import qualified Data.ByteString as BS 

When I try to load the file, it complains: 当我尝试加载文件时,它抱怨:

:l ./src/Families.hs
[1 of 1] Compiling Families         ( src/Families.hs, interpreted )

src/Families.hs:6:1: error:
    Could not load module ‘Data.ByteString’
    It is a member of the hidden package ‘bytestring-0.10.8.2’.
    You can run ‘:set -package bytestring’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v to see a list of the files searched for.
  |
6 | import qualified Data.ByteString as BS
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.

The question is, how to reload the whole project into the GHCi and allow usage of bytestring library. 问题是,如何将整个项目重新加载到GHCi中并允许使用bytestring库。

UPDATE UPDATE
I also tried with :reload and got 我也尝试了:reload并得到了

:reload
[1 of 1] Compiling Families         ( src/Families.hs, interpreted )

src/Families.hs:6:1: error:
    Could not load module ‘Data.ByteString’
    It is a member of the hidden package ‘bytestring-0.10.8.2’.
    You can run ‘:set -package bytestring’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v to see a list of the files searched for.
  |
6 | import qualified Data.ByteString as BS
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.

I see you are using Spacemacs along with intero . 我看到您正在将Spacemacs与intero一起使用。 In this case you may restart whole intero process by typing Mx intero-restart RET , or M-RET ir which will reload all stack dependencies. 在这种情况下,您可以通过键入Mx intero-restart RETM-RET ir重新启动整个内部操作过程,这将重新加载所有堆栈依赖项。

Another way to do this is to put your cursor on the error import and type Cc Cr to let the intero automatically fix the issue. 执行此操作的另一种方法是将光标放在错误导入上,然后键入Cc Cr以让intero自动解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM