网络书屋(Web Reading Room)

A blogging framework for hackers.

Haskell的IO Main

main在Haskell充当类似c系列语言的exe文件的头函数 main对应的类型是IO Something 比如下列源码:

1
2
3
4
5
main = do
    putStrLn "Hello Hello"
    putStrLn "Hello, what's your name?"
    name <- getLine
    putStrLn $ "Read this carefully, because this is your future: " ++  name

Windows 输出:

1
2
3
4
5
6
7
8
9
c:\>ghc --make hello.hs -o Hello
[1 of 1] Compiling Main             ( hello.hs, hello.o )
Linking Hello.exe ...

c:\>Hello.exe
Hello Hello
Hello, what's your name?
yezhaoliang
Read this carefully, because this is your future: yezhaoliang

Ubuntu 输出:

1
2
3
4
5
6
7
8
9
10
11
root at javazhao-N53SM [21:52:10ä��午] in /home/happycamp-of-lisp on git:develop+?
$ ghc --make hello12.hs -o hello12
[1 of 1] Compiling Main ( hello12.hs, hello12.o )
Linking hello12 ...

root at javazhao-N53SM [21:52:25ä��午] in /home/happycamp-of-lisp on git:develop+?
$ ./hello12
Hello Hello
Hello, what's your name?
yezhaoliang
Read this carefully, because this is your future: yezhaoliang

Haskell天生的具备跨平台的特点