70 %
Chris Biscardi

Your first Haskell Program

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.hs
haskell
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 print and passes it a string literal to print out to the console.

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.

shell
➜ ghci main.hs
GHCi, version 8.6.3: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /Users/chris/.ghci
[1 of 1] Compiling Main ( main.hs, interpreted )
Ok, one module loaded.
λ: main
"helllloooo"