2016-09-07 23 views
8

Jestem nowym Haskell i mam problem uruchomiony następujący kod:Uruchamianie i kompilowanie 'Hello, World!' w Haskell

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

SublimeHaskell próbuje skompilować i uruchomić powyżej używając

runhaskell hello.hs 

który zwraca błąd

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

Próbowałem również uruchomić go przy użyciu

ghc --make hello.hs 

z tym samym błędem. Gdy próbuję ręcznie skompilować kod przed uruchomieniem za pomocą wiersza polecenia

ghc -c hello.hs 

otrzymuję inny błąd:

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

Z drugiej strony, można uruchomić program z REPL bez problemu:

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

Jeśli jest to istotne, używam systemu Windows 7, a ja zainstalowałem GHC przy użyciu instalatora platformy Haskell.

*** edit działa powyższe polecenia z flagą -v daje następujące wyniki:

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.) 

Po rozglądając się, wydaje się, że dwa pakiety, które są wymienione jako nie stwierdzono (dph-seq i dph-par) mają został przestarzały.

+5

No tak, to z pewnością istotne, że używasz systemu Windows 7. I tak jest ekosystem Haskell - Jak zainstalować GHC? Z stosem lub w inny sposób? ... Wiem, że nie powinienem, ale nie mogę powstrzymać się od rekomendacji, aby po prostu przełączyć się na dystrybucję Linuksa, aby zdecydowanie pozbyć się takich kłopotów. (Ale słyszałem, że GHC ze stosem powinno być teraz łatwe nawet w Windowsie, więc ...) – leftaroundabout

+1

Czy twój dysk jest pełny? –

+0

Niestety, utknąłem z Windows na razie zainstalowałem GHC przy użyciu instalatora platformy Haskell. Dysk nie ma jeszcze ~ 8 GB wolnego miejsca. – Fortunato

Odpowiedz

0

GHC wymaga, aby plik był nazwany tak samo jak moduł, aby go skompilować. Jednak każdy moduł można załadować do GHCi niezależnie od nazwy pliku. Właśnie dlatego repl działał, ale kompilacja go nie działała.

W twoim przypadku, w związku z tym, należy zmienić nazwę pliku Main.hs