2016-09-24 122 views
1

我想在這裏學習haskell(不要問爲什麼),而我從一個非常簡單的代碼開始,我甚至從github複製。堆棧無法建立

因此,代碼是這樣的:

module Example() where 

import Network.HTTP 

-- Non HTTPS 

-- 1. Perform a basic HTTP get request and return the body 
get :: String -> IO String 
get url = simpleHTTP (getRequest url) >>= getResponseBody 

-- 2. Get the response code 
getCode :: String -> IO ResponseCode 
getCode url = simpleHTTP req >>= getResponseCode 
    where req = getRequest url 

然而,當我運行stack build我得到這個:

slack-client-0.1.0.0: build 
Preprocessing library slack-client-0.1.0.0... 
[2 of 2] Compiling Example   (src\Example.hs, .stack-work\dist\b7fec021\ 
build\Example.o) 

D:\haskell\slack-client\src\Example.hs:3:1: error: 
    Failed to load interface for `Network.HTTP' 
    It is a member of the hidden package `HTTP-4000.3.3'. 
    Perhaps you need to add `HTTP' to the build-depends in your .cabal file. 
    Use -v to see a list of the files searched for. 

-- While building package slack-client-0.1.0.0 using: 
     C:\Users\Mihai\AppData\Roaming\stack\setup-exe-cache\x86_64-windows\setup- 
Simple-Cabal-1.24.0.0-ghc-8.0.1.exe --builddir=.stack-work\dist\b7fec021 build l 
ib:slack-client exe:slack-client-exe --ghc-options " -ddump-hi -ddump-to-file" 
    Process exited with code: ExitFailure 1 

這是我.cabal文件:

name:    slack-client 
version:    0.1.0.0 
synopsis:   Initial project template from stack 
description:   Please see README.md 
homepage:   https://github.com/githubuser/slack-client#readme 
license:    BSD3 
license-file:  LICENSE 
author:    Author name here 
maintainer:   [email protected] 
copyright:   2016 Author name here 
category:   Web 
build-type:   Simple 
-- extra-source-files: 
cabal-version:  >=1.10 

library 
    hs-source-dirs:  src 
    exposed-modules:  Lib 
    other-modules:  Example 
    build-depends:  base >= 4.7 && < 5 
    default-language: Haskell2010 

executable slack-client-exe 
    hs-source-dirs:  app 
    main-is:    Main.hs 
    other-modules:  Example 
    ghc-options:   -threaded -rtsopts -with-rtsopts=-N 
    build-depends:  base 
        , HTTP 
        , HTTP-Simple 
        , slack-client 
    default-language: Haskell2010 

test-suite slack-client-test 
    type:    exitcode-stdio-1.0 
    hs-source-dirs:  test 
    main-is:    Spec.hs 
    build-depends:  base 
        , HTTP-Simple 
        , slack-client 
    ghc-options:   -threaded -rtsopts -with-rtsopts=-N 
    default-language: Haskell2010 

source-repository head 
    type:  git 
    location: https://github.com/githubuser/slack-client 

我是什麼做錯了?

+0

'module Example()where'should read'module Example where或'module Example(get,getCode)where'。因爲它是從'Example'輸出什麼都沒有(你定義的任何類實例都會被導出,因爲類的特殊工作方式。) – Michael

+0

@Michael thanks!但是,這並不能解決問題。 – Comforse

回答

1

如果你想你`實例模塊可被執行的一部分,添加到本節

executable slack-client-exe 
    hs-source-dirs:  app 
    main-is:    Main.hs 

這一行:other-modules: Example

如果你希望它是圖書館的一部分,改變

library 
    hs-source-dirs:  src 
    exposed-modules:  Lib 

library 
    hs-source-dirs:  src 
    exposed-modules:  Lib, Example 

而且看看cabal documentation

+0

試過每個選項,得到相同的錯誤。我需要運行「堆棧構建」以外的其他任何東西嗎? – Comforse

+0

您是否將'Example.hs'移動到'src'中,並從'slack-client-exe'的節中刪除它?自'Example'使用它之後,您需要將'HTTP'添加到庫的'build-depends'。錯誤消息是說它知道一個模塊「Network.HTTP」,但不允許查看它,因爲沒有提到'HTTP'庫。 – Michael