Chap2. 准备行李箱 Getting Started

有三种常用的 Haskell 系统: GHC, Hugs, NHC 。 Hugs只能解释执行,而 ghc 可以编译成独立程序。他们都有交互式的环境(hugs, ghci), NHC是一个编译器(没有用过呢)。

Hugs非常的轻巧,速度很快,适合调试。
GHC这个则是实际开发中比较重量级的产品了。对于标准和扩展库的实现也是最好的。

具体的下载以及使用看书吧(好懒啊~~),不过这里给出我的配置:

系统: Ubuntu Linux 6.10
haskell: 下载 ghc-6.6 自己编译 (现在的 apt 里面带的是 6.4.2版本)
editor: Emacs-23 + haskell-mode (这个比较重要,一个好的编辑器写程序绝对是享受)

关于 emacs 的配置,可以看: 在 Ubuntu 6.10 下安装 emacs 23 (unicode-2 branch) 版本 一文。

安装好 haskell-mode , 在 Emacs 中打开或编辑一个 .hs , .lhs 后缀的文件,就可以进入 haskell-mode ,语法加亮,自动对齐等功能一样不能少。按 Ctrl + c z ,进入haskell交互模式,然后输入 :l 文件名 就可以把程序调入,然后进行调试。这样上半个窗口写程序,下半个窗口调试,多熟悉下就适应了。

怎样编译一个程序? Hello world 出场:

albert@albert-laptop:~/develop/haskell$ cat hello_world.hs

module Main where
main = putStrLn "Hello world"

albert@albert-laptop:~/develop/haskell$ ghc --make hello_world.hs -o hello_world
[1 of 1] Compiling Main ( hello_world.hs, hello_world.o )
Linking hello_world ...

albert@albert-laptop:~/develop/haskell$ ./hello_world
Hello world

----
准备好家伙,继续上路了