Haskell : First project - Hello World

·

1 min read

1. in the ghci , you can use GHC complier

ghci> putStrLn "Hello World!"
Hello, World!
ghci>

2. Use IDE, save a file named helloworld.js

main :: IO ()
main = putStrLn "Hello, World!"

The first line is an optional type annotation, indicating that main is a value of type IO (), representing an I/O action which "computes" a value of type () (read "unit"; the empty tuple conveying no information) besides performing some side effects on the outside world (here, printing a string at the terminal). This type annotation is usually omitted for main because it is its only possible type.

Then in the cmd , go to project folder, use GHC compile it.

D:\Haskell>ghc helloworld.hs
[1 of 1] Compiling Main             ( helloworld.hs, helloworld.o )
Linking helloworld.exe ...

Executing the compiled file will result in the output "Hello, World!" being printed to the screen:

D:\Haskell>helloworld  
Hello, World!

Resource:
riptutorial.com/haskell/example/898/hello--..