Ber*_*ian 2 haskell visual-studio-code haskell-stack
您好,我尝试将Haskell与vscode一起使用,如果我尝试在另一个模块中使用模块,则会出现以下错误:
Failed to load interface for **Client**
Use -v to see a list of the files searched for.
Run Code Online (Sandbox Code Playgroud)
第一个模块:
module Main where
import qualified Client as Cl
main ::IO ()
main = do
name<- getLine
sp
Run Code Online (Sandbox Code Playgroud)
第二个模块:
module Client
(sp)where
sp::IO()
sp=print "SecondModule"
Run Code Online (Sandbox Code Playgroud)
经过一番阅读后,我尝试更新堆栈并安装构建工具,此时出现以下错误:
$ stack install gtk2hs-buildtools
?[0mprimitive-0.6.3.0: using precompiled package?[0m
?[0mCabal-2.0.1.1: using precompiled package?[0m
?[0mmtl-2.2.1: using precompiled package?[0m
?[0mrandom-1.1: using precompiled package?[0m
?[0mtext-1.2.2.2: using precompiled package?[0m
?[0mvector-0.12.0.1: using precompiled package?[0m
?[0mtf-random-0.5: configure?[0m
?[0mhashable-1.2.6.1: using precompiled package?[0m
?[0mhappy-1.19.9: download?[0m
?[0mtf-random-0.5: build?[0m
?[0mhashtables-1.2.2.1: download?[0m
?[0mhashtables-1.2.2.1: configure?[0m
?[0mhashtables-1.2.2.1: build?[0m
?[0mhappy-1.19.9: configure?[0m
?[0mtf-random-0.5: copy/register?[0m
?[0mQuickCheck-2.10.1: download?[0m
?[0mhappy-1.19.9: build?[0m
?[0mQuickCheck-2.10.1: configure?[0m
?[0mQuickCheck-2.10.1: build?[0m
?[0mhashtables-1.2.2.1: copy/register?[0m
?[0mQuickCheck-2.10.1: copy/register?[0m
?[0malex-3.2.3: download?[0m
?[0malex-3.2.3: configure?[0m
?[0malex-3.2.3: build?[0m
?[0mhappy-1.19.9: copy/register?[0m
?[0malex-3.2.3: copy/register?[0m
?[0mgtk2hs-buildtools-0.13.3.1: download?[0m
?[0mgtk2hs-buildtools-0.13.3.1: configure?[0m
?[0mgtk2hs-buildtools-0.13.3.1: build?[0m
?[0mgtk2hs-buildtools-0.13.3.1: copy/register?[0m
Completed 13 action(s).
removeDirectoryRecursive:removeContentsRecursive:removePathRecursive:removeContentsRecursive:removePathRecursive:removeContentsRecursive:removePathRecursive:removeContentsRecursive:removePathRecursive:removeContentsRecursive:removePathRecursive:removeContentsRecursive:removePathRecursive:DeleteFile "C:\\Users\\aita\\AppData\\Local\\Temp\\stack7744\\gtk2hs-buildtools-0.13.3.1\\.stack-work\\dist\\5c8418a7\\build\\gtk2hsC2hs\\gtk2hsC2hs.exe": permission denied (The process cannot access the file because it is being used by another process.)
Run Code Online (Sandbox Code Playgroud)
我很小心,不要让其他进程使用此文件夹,但是我不明白为什么会出错。
这是我的stack.yaml文件:
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# https://docs.haskellstack.org/en/stable/yaml_configuration/
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
# resolver: ghcjs-0.1.0_ghc-7.10.2
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-10.7
# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
# git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# extra-dep: true
# subdirs:
# - auto-update
# - wai
#
# A package marked 'extra-dep: true' will only be built if demanded by a
# non-dependency (i.e. a user package), and its test suites and benchmarks
# will not be run. This is useful for tweaking upstream packages.
packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
# extra-deps: []
# Override default flag values for local packages and extra-deps
# flags: {}
# Extra package databases containing global packages
# extra-package-dbs: []
# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.6"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
Main
Client
Run Code Online (Sandbox Code Playgroud)
阴谋文件。
name: Hworld
version: 0.1.0.0
-- synopsis:
-- description:
homepage: https://github.com/githubuser/Hworld#readme
license: BSD3
license-file: LICENSE
author: Author name here
maintainer: example@example.com
copyright: 2018 Author name here
category: Web
build-type: Simple
cabal-version: >=1.10
extra-source-files: README.md
executable Hworld
hs-source-dirs: src
main-is: Main.hs
default-language: Haskell2010
build-depends: base >= 4.7 && < 5
Run Code Online (Sandbox Code Playgroud)
首先,stack install有点用词不当。不同于npm install或bower install,它不会下载任何内容或“添加”任何东西到您的项目中。在下stack,所有软件包(可能是逻辑上)始终被下载和安装。stack会在首次使用时构建一个程序包,但无需明确要求stack下载它。
什么stack install实际上做,它建立的包,如果包中包含任何可执行文件,这使他们在文件系统上的一个特殊的地方,那就是你的PATH,所以现在你可以运行这些可执行文件。除非您确实确定有必要,否则通常不建议您查看如何始终在stack exec package不安装可执行文件的情况下运行可执行文件stack install。
要将软件包添加到项目中,您需要将其包含.cabal在build-depends部分中的package.yaml文件中或部分中的文件中dependencies(无论使用哪个)。下面是一个例子package.yaml,并且这里有一个示例.cabal文件。
但是,看来您要尝试的是引用自己的模块,而不是外部依赖项。为此,stack install甚至与事实相去甚远。
要引用自己的模块,您需要做两件事:(1)正确的文件系统结构和(2)将它们添加到.cabal或中package.yaml。
文件系统结构:在Haskell(或更确切地说,在GHC中)中,模块必须位于文件系统上与其层次结构名称相匹配的位置。例如,模块Main将位于中./Main.hs,模块Client将位于中./Client.hs,或者说模块Client.Internals将位于中./Client/Internals.hs。有点烦人,是的。但这就是Haskell的方式。
阴谋文件:包/库中的所有模块都必须在.cabal文件中列出,在下方exposed-modules或下方other-modules。只需在此处添加它们,编译器就会看到它们。
| 归档时间: |
|
| 查看次数: |
1057 次 |
| 最近记录: |