Here is a Haskell program that prints out "helllloooo" to the console when run. We put this in a file with a
.hs file extension and by convention use
main as the filename.
main :: IO ()main = print "helllloooo"
We name our function
main and use two lines to define it. These lines are split into the type signature, which tells us what arguments the function takes as well as what it returns, and the function body definition. The function body is what you might be used to writing in other languages.
The type we use is
IO (). The parens are pronounced "unit".
The function body uses a function from what we call the Prelude, or standard library called
We can then load this file into
ghci, which is Haskell's main compiler's (ghc) interactive environment. If we run the file we load by typing
main, we can see the value print out.
➜ ghci main.hsGHCi, version 8.6.3: http://www.haskell.org/ghc/ :? for helpLoaded GHCi configuration from /Users/chris/.ghci[1 of 1] Compiling Main ( main.hs, interpreted )Ok, one module loaded.λ: main"helllloooo"