到haskell官方下载haskell的工具包:

https://downloads.haskell.org/~platform/2014.2.0.0/Haskell%20Platform%202014.2.0.0%2064bit.signed.pkg

adeMacBook-Pro:haskell_dev apple$ ghci
GHCi, version : http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> putStrLn "Hello World"
Hello World
Prelude> 

参考文档:

http://rwh.readthedocs.org/en/latest/chp/1.html

解析:

把下面这段代码保存成SimpleJSON.hs

-- file: ch05/SimpleJSON.hs
data JValue = JString String
| JNumber Double
| JBool Bool
| JNull
| JObject [(String, JValue)]
| JArray [JValue]
deriving (Eq, Ord, Show)

-- file: ch05/SimpleJSON.hs
getString :: JValue -> Maybe String
getString (JString s) = Just s
getString _ = Nothing

-- file: ch05/SimpleJSON.hs
getInt (JNumber n) = Just (truncate n)
getInt _ = Nothing

getDouble (JNumber n) = Just n
getDouble _ = Nothing

getBool (JBool b) = Just b
getBool _ = Nothing

getObject (JObject o) = Just o
getObject _ = Nothing

getArray (JArray a) = Just a
getArray _ = Nothing

isNull v = v == JNull

main = print (JObject [("foo", JNumber 1), ("bar", JBool False)])

然后在ghci中把add.hs加载进去就可以了:

adeMacBook-Pro:haskell_dev apple$ ghci

GHCi, version 7.8.3: http://www.haskell.org/ghc/  :? for help

Loading package ghc-prim ... linking ... done.

Loading package integer-gmp ... linking ... done.

Loading package base ... linking ... done.

Prelude> :load SimpleJSON.hs

[1 of 1] Compiling Main             ( SimpleJSON.hs, interpreted )

Ok, modules loaded: Main.

*Main> getString (JString "hello")

Just "hello"

*Main>  getString (JNumber 3)

Nothing

*Main> getString (JString "hello")

Just "hello"

*Main>

编译haskell 

adeMacBook-Pro:haskell_dev apple$ ls

Assign.hs       InteractWith.hi SimpleJSON.hs   WC.o            myDrop.hs

BookStore.hs    InteractWith.hs WC              add.hs          quux.txt

HelloWorld.hs   InteractWith.o  WC.hi           hello-in.txt    upperCase.hs

InteractWith    Maybe           WC.hs           hello-out.txt

adeMacBook-Pro:haskell_dev apple$ ghc SimpleJSON.hs

[1 of 1] Compiling Main             ( SimpleJSON.hs, SimpleJSON.o )

Linking SimpleJSON ...

adeMacBook-Pro:haskell_dev apple$ ls

Assign.hs       InteractWith.hs SimpleJSON.hs   WC.o            quux.txt

BookStore.hs    InteractWith.o  SimpleJSON.o    add.hs          upperCase.hs

HelloWorld.hs   Maybe           WC              hello-in.txt

InteractWith    SimpleJSON      WC.hi           hello-out.txt

InteractWith.hi SimpleJSON.hi   WC.hs           myDrop.hs

adeMacBook-Pro:haskell_dev apple$ ls

Assign.hs       InteractWith.hs SimpleJSON.hs   WC.o            quux.txt

BookStore.hs    InteractWith.o  SimpleJSON.o    add.hs          upperCase.hs

HelloWorld.hs   Maybe           WC              hello-in.txt

InteractWith    SimpleJSON      WC.hi           hello-out.txt

InteractWith.hi SimpleJSON.hi   WC.hs           myDrop.hs

adeMacBook-Pro:haskell_dev apple$ ./SimpleJSON

JObject [("foo",JNumber 1.0),("bar",JBool False)]

使用runghc执行:

adeMacBook-Pro:haskell_dev apple$ runghc SimpleJSON.hs

JObject [("foo",JNumber 1.0),("bar",JBool False)]

最新文章

  1. MongoDB学习笔记五—查询上
  2. 传智播客--数据绑定--INotifyPropertyChanged(小白内容)
  3. Linux-001-nmon系统性能监控工具的使用及报表产出
  4. 《精通C#》委托与事件(10章)
  5. Mybatis中SqlMapper配置的扩展与应用(1)
  6. IIS8中部署WCF服务出错:HTTP 错误 404.3 - Not Found
  7. Hadoop实战课程
  8. Maven3.0 服务器配置搭建
  9. ubuntu下的翻译软件goldendict
  10. Sublime Text 3 LESS、SASS、SCSS高亮插件、提示插件
  11. docker学习笔记:容器的网络设置
  12. 编译filezilla
  13. 通过Visualizing Representations来理解Deep Learning、Neural network、以及输入样本自身的高维空间结构
  14. OpenStack VS Kubernetes,谁是你心中的王者?
  15. WebBrowser2控件使用
  16. grep正则表达式搜索
  17. svn 锁的处理
  18. poj-2513(字典树+欧拉通路)
  19. vue-cli3 第三版安装搭建项目
  20. [BZOJ3585]mex(莫队+分块)

热门文章

  1. VS2010+OpenCV2.4.6永久性配置方法
  2. TreeSet里面放对象,如果同时放入了父类和子类的实例对象,那比较时使用的是父类的compareTo方法,还是使用的子类的compareTo方法,还是抛异常!
  3. 看了让人笑了很多很多次的NB的痔疮经历
  4. 如何用rake tasks 生成migration对应的sql
  5. HTML 快速入门
  6. django revision
  7. 在 FREEBUF 投放广告
  8. dom 中事件
  9. Android 中4种屏幕尺寸
  10. 基于Delphi的三层数据库系统的实现方法