Wednesday 20 May 2015

Hello World Again!

The Haskell team have done what the Erlang guys did - created a single block of resources that can be downloaded as a massive package that gives you everything you need to get started.

Via www.haskell.org there is a "Haskell Platform" that takes the form of a 130 MB download - not long ago I would not have had room to store that much, let alone consider downloading it - -

This gives you a setup.exe that installs the toolkit.  Solution.  Platform.

Well also I will need the Haskell mode for Emacs but I find I have this already. I can't remember where I got this from, I've copied the files over from another machine from one of the previous times that I decided finally to learn Haskell and never got anywhere. Twas ever thus.

Anyway, the minimum Hello World program in Haskell looks like this:

main = putStrLn "Hello World"

main of course indicates to the compiler that this is the entry point of the code: and all we do is call a function that emits a given string to the terminal.

I've put this in a file called hello.hs

To compile, start DOS:

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\polly>cd documents\projects\haskell
C:\Users\polly\Documents\projects\haskell>prompt $G
>dir
 Volume in drive C is Windows
 Volume Serial Number is 20F4-549E

 Directory of C:\Users\polly\Documents\projects\haskell

02/05/2015  11:24    <DIR>          .
02/05/2015  11:24    <DIR>          ..
02/05/2015  11:25             2,397 #notes.txt#
02/05/2015  11:24                31 hello.hs
02/05/2015  11:17             2,024 notes.txt
02/05/2015  11:05               860 notes.txt~
               8 File(s)          9,788 bytes
               2 Dir(s)  88,518,500,352 bytes free

>ghc --make hello.hs -o hello.exe
[1 of 1] Compiling Main             ( hello.hs, hello.o )
Linking hello.exe ...

ghc is the compiler: we supply the source file name and the name of the executable (flag -o) that we want to create.  Results:

>dir
 Volume in drive C is Windows
 Volume Serial Number is 20F4-549E

 Directory of C:\Users\polly\Documents\projects\haskell

02/05/2015  11:27    <DIR>          .
02/05/2015  11:27    <DIR>          ..
02/05/2015  11:25             2,397 #notes.txt#
02/05/2015  11:27         1,950,052 hello.exe
02/05/2015  11:27               544 hello.hi
02/05/2015  11:24                31 hello.hs
02/05/2015  11:27             1,772 hello.o
02/05/2015  11:17             2,024 notes.txt
02/05/2015  11:05               860 notes.txt~
              11 File(s)      1,962,156 bytes
               2 Dir(s)  88,516,456,448 bytes free

And then we can run it:

>hello
Hello World

No comments:

Post a Comment