I’d like to start learning haskell and I cannot get it to work, so basically I have installed the stack, created a new project using the stack new command.I also run stack update, stack upgrade.And now I have an app folder, a source folder and much more stuff.I genuinely admit that I have absolutely no idea of what I am doing however I have seen in the docs that each command and the stack itself are all very well explained.However that is a quite theoretical explanation, I am just trying to run my first hello world program as I always did in every programming language I have learnt so far :).Could you help me?This is a screenshot with the current structure of my project directory.Image of dir structure.As you can see I also tried to run the ghc or ghci commands but without any luck.Thanks in advance ;)
CodePudding user response:
I'm gonna post a somewhat controversial opinion here, and say that if what you want is a hello-world with a minimum of fuss, then stack is not the right tool. Just use GHC directly. Simply make a file, say, hello.hs
, that contains:
main = putStrLn "Hello, world!"
Then at the command line, here are some things you can do to run it; there are three options here, and you only need to choose one.
% runhaskell hello.hs
Hello, world!
% ghc hello.hs
[1 of 1] Compiling Main ( test.hs, test.o )
Linking hello ...
% ./hello
Hello, world!
% ghci hello.hs
> main
Hello, world!
You may need to tweak some commands slightly if you are on Windows; the main one I think is that ./hello
would be hello.exe
.