2016-09-07 4 views
8

に私はHaskellのに新しいですし、次のコード実行中の問題を抱えています:「Hello、World!」の実行とコンパイルHaskellの

module Main (
main 
) where 
main = putStrLn "Hello, world!" 

SublimeHaskellをコンパイルしてエラーを返し

runhaskell hello.hs 

使用して、上記実行しようとし

hello.o: getModificationTime: invalid argument (The system cannot find the file specified.) 

私も実行しようとしました

ghc --make hello.hs 

同じエラーがあります。私は手動でコマンドライン

ghc -c hello.hs 

を使用して実行する前に、コードをコンパイルしようとすると、私は別のエラーが出る:一方

CreateDirectory ".": invalid argument (Cannot create a file when that file already exists.) 

を、私は問題なくREPLを経由してプログラムを実行することができます。

ghci 
GHCi, version 8.0.1: http://www.haskel.org/ghc/ :? for help 
Prelude> putStrLn "Hello, world!" 
Hello, world! 

私はWindows 7を使用していますが、Haskell Platformインストーラを使用してGHCをインストールしました。 -vフラグで上記のコマンドを実行している

***編集は、以下の結果得られます。周りを見た後

ghc -v hello.hs 

Glasgow Haskell Compiler, Version 8.0.1, stage 2 booted by GHC version  7.10.2 
Using binary package database: C:\Program Files\Haskell  Platform\8.0.1\lib\package.conf.d\package.cache 
loading package database C:\Program Files\Haskell Platform\8.0.1\lib\package.conf.d 
wired-in package ghc-prim mapped to ghc-prim-0.5.0.0 
wired-in package integer-gmp mapped to integer-gmp-1.0.0.1 
wired-in package base mapped to base-4.9.0.0 
wired-in package rts mapped to rts 
wired-in package template-haskell mapped to template-haskell-2.11.0.0 
wired-in package ghc mapped to ghc-8.0.1 
wired-in package dph-seq not found. 
wired-in package dph-par not found. 
Hsc static flags: 
loading package database C:\Program Files\Haskell  Platform\8.0.1\lib\package.conf.d 
wired-in package ghc-prim mapped to ghc-prim-0.5.0.0 
wired-in package integer-gmp mapped to integer-gmp-1.0.0.1 
wired-in package base mapped to base-4.9.0.0 
wired-in package rts mapped to rts-1.0 
wired-in package template-haskell mapped to template-haskell-2.11.0.0 
wired-in package ghc mapped to ghc-8.0.1 
wired-in package dph-seq not found. 
wired-in package dph-par not found. 
*** Chasing dependencies: 
Chasing modules from: *hello.hs 
*** Deleting temp files: 
Deleting: 
*** Deleting temp dirs: 
Deleting: 
hello.o: getModificationTime: invalid argument (The system cannot find the file specified.) 

ghc -c -v hello.hs 

Glasgow Haskell Compiler, Version 8.0.1, stage 2 booted by GHC version 7.10.2 
Using binary package database: C:\Program Files\Haskell  Platform\8.0.1\lib\package.conf.d\package.cache 
loading package database C:\Program Files\Haskell Platform\8.0.1\lib\package.conf.d 
wired-in package ghc-prim mapped to ghc-prim-0.5.0.0 
wired-in package integer-gmp mapped to integer-gmp-1.0.0.1 
wired-in package base mapped to base-4.9.0.0 
wired-in package rts mapped to rts 
wired-in package template-haskell mapped to template-haskell-2.11.0.0 
wired-in package ghc mapped to ghc-8.0.1 
wired-in package dph-seq not found. 
wired-in package dph-par not found. 
Hsc static flags: 
*** Checking old interface for Main: 
*** Parser [Main]: 
!!! Parser [Main]: finished in 0.00 milliseconds, allocated 0.067 megabytes 
*** Renamer/typechecker [Main]: 
!!! Renamer/typechecker [Main]: finished in 46.80 milliseconds, allocated 15.720 megabytes 
*** Desugar [Main]: 
Result size of Desugar (after optimization) 
= {terms: 13, types: 6, coercions: 0} 
!!! Desugar [Main]: finished in 0.00 milliseconds, allocated 0.204 megabytes 
*** Simplifier [Main]: 
Result size of Simplifier iteration=1 
= {terms: 17, types: 8, coercions: 0} 
Result size of Simplifier = {terms: 17, types: 8, coercions: 0} 
!!! Simplifier [Main]: finished in 0.00 milliseconds, allocated 0.171 megabytes 
*** CoreTidy [Main]: 
Result size of Tidy Core = {terms: 17, types: 8, coercions: 0} 
!!! CoreTidy [Main]: finished in 0.00 milliseconds, allocated 2.558 megabytes 
*** Deleting temp files: 
Deleting: 
*** Deleting temp dirs: 
Deleting: 
CreateDirectory ".": invalid argument (Cannot create a file when that file already exists.) 

を、見つからないとしてリストされている2つのパッケージ(dph-seqdph-par)を持っているようです推奨されていません。

+5

の名前を変更する必要がありますまあ、はい、それはあなたがWindows 7を使用していることは間違いなく、関連だとそうHaskellの生態系がある - どのようにGHCをインストールしたのですか?スタック、または他の方法で? ...私はすべきではないことは分かっていますが、Linuxディストリビューションに切り替えるだけで、そのような問題を確実に取り除くことを推奨できません。 (でも、GHCスタックはWindowsでも簡単だと聞いたので...) – leftaroundabout

+1

ドライブはいっぱいですか? –

+0

残念ながら、私はHaskell Platformインストーラを使用してGHCをインストールしている間は、Windowsに悩まされています。ドライブがいっぱいではありません〜8GBのスペースが残っています。 – Fortunato

答えて

0

GHCでは、ファイルをコンパイルするためにモジュールと同じ名前を付ける必要があります。 しかし、ファイル名に関係なく、どのモジュールもGHCiにロードできます。これはreplが働いたがコンパイルしなかった理由である。あなたのケースでは

は、したがって、あなたはファイルMain.hs