到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)]

Mac OS X 上的安装haskell开发环境的更多相关文章

  1. Mac OS X 上的安装Lisp开发环境

    到网站:https://common-lisp.net/project/lispbox/ 下载lispbox 解压下载下来的包,找到Emacs 测试: 我们也可以使用homebrew来安装lisp的解 ...

  2. Mac OS X 上的安装Lua开发环境

    测试Lua环境是否已经安装: adeMacBook-Pro:perl_dev apple$ lua -bash: lua: command not found 如果没有的话就到lua官方去下载:(网址 ...

  3. Sqlite在Windows、Linux 和 Mac OS X 上的安装过程

    一:在 Windows 上安装 SQLite 1,下载 请访问SQLite下载页面http://www.sqlite.org/download.html,从Windows 区下载预编译的二进制文件.需 ...

  4. Swig在Mac OS X上的安装

    网上有很多类似文章介绍Swig怎么在Mac OS X上安装和配置,一般来说就是: 下载pcre,configure & make & make install 下载swig,confi ...

  5. go语言系列--golang在windows上的安装和开发环境goland的配置

    在windows上安装golang软件 golang中国网址为:https://studygolang.com/dl 我的学习选择版本:1.12.5 golang 1.12.5版本更新的内容:gola ...

  6. 【转】搭建Mac OS X下cocos2d-x的Android开发环境

    http://young40.github.io/blog/2013/02/23/setting-up-android-development-envirment-on-mac-os-x/ http: ...

  7. 金玉良缘易配而木石前盟难得|M1 Mac os(Apple Silicon)天生一对Python3开发环境搭建(集成深度学习框架Tensorflow/Pytorch)

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_189 笔者投入M1的怀抱已经有一段时间了,俗话说得好,但闻新人笑,不见旧人哭,Intel mac早已被束之高阁,而M1 mac已经 ...

  8. 如何在Mac OS系统下配置Java服务器开发环境

    1.http://www.oracle.com/technetwork/Java/javase/downloads/index-jsp-138363.html 安装JDK(可通过java -versi ...

  9. Mac OS 10.8 中的 OpenCV 开发环境设置

    一.编译OpenCV 要在Mac OS上使用OpenCV,需要自己编译源代码.操作过程如下: 1)从http://www.cmake.org下载cmake 2.8安装包. 2)安装cmake 2.8. ...

随机推荐

  1. linux下python版webshell后门查杀工具

    使用说明: 1.查杀指定路径:python webshell.py 路径 2.按时间查找文件:python webshell.py 路径 “2013-09-28 00:00:00″ # -*- cod ...

  2. ASP.NET版Memcached监控工具(转载)

    在上一篇文章<使用Memcached提高.NET应用程序的性能>中周公讲述如何在.NET中使用Memcached来提高.NET应用程序的性 能.在实际的使用中有可能出现Memcached因 ...

  3. Javascript的调试利器:Firebug使用详解

    转载自:http://blog.csdn.net/tianxiaode/archive/2007/09/02/1769152.aspx   一直在用firebug,可是没有这么精通,今天看到本文章觉得 ...

  4. centos安装软件Error: Cannot find a valid baseurl for repo: base

    今天使用yum安装软件,出现下面的提示: Loaded plugins: fastestmirror, refresh-packagekit, securityLoading mirror speed ...

  5. 转 Citrix XenCenter安装VM之挂载ISO详解

    转自:http://www.2cto.com/os/201302/190713.html 环境信息:XenServer Version:6.0.2XenCenter Version:6.0.2NFS ...

  6. javascript中parentNode,childNodes,children的应用详解

    本篇文章是对javascript中parentNode,childNodes,children的应用进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助   "parentNode&qu ...

  7. Encapsulation and Requiring Files

    By encapsulating all the logic for an object, whether it’s a Dog or a User or an IceCreamShop, you a ...

  8. previous_changes方法

    [27] pry(main)> c = Channel.find 6 => #<Channel id: 6, title: "会员", cid: "96 ...

  9. python 之验证码

    验证码原理在于后台自动创建一张带有随机内容的图片,然后将内容通过img标签输出到页面. 安装图像处理模块: pip3 install pillow

  10. javascript memoization递归优化

    memoize优化递归 function createRec(callback, cache) { cache = cache || []; var rec = function(n) { (n in ...