Haskell的IO main

Reading time: 0 minutes and 59 seconds with 218 words. 本文总阅读量

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

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

Windows 输出:

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 输出:

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天生的具备跨平台的特点

Avatar
Ye Zhaoliang
Engineer of offshore wind turbine technique research

My research interests include distributed energy, wind turbine power generation technique , Computational fluid dynamic and programmable matter.

Related

本站访问量: