到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. JS 瀑布流布局

    瀑布流布局 HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"> &l ...

  2. linux ftp命令(转)

    此命令需要安装ftp, yum install ftp 1. 连接ftp服务器 格式:ftp [hostname| ip-address]a)在linux命令行下输入: ftp 192.168.1.1 ...

  3. Log4Net日志记录两种方式

     简介 log4net库是Apache log4j框架在Microsoft .NET平台的实现,是一个帮助程序员将日志信息输出到各种目标(控制台.文件.数据库等)的工具.     log4net是Ap ...

  4. 关于设置SQLPLUS提示符样式的方法----登陆配置文件,动态加载提示符

    工作中用到 sqlplus mdsoss/mdsoss, 所以来了解一下sqlplus (C shell .cshrc文件里中alisa) 关于设置SQLPLUS提示符样式的方法 12638阅读 1评 ...

  5. 安装lnmp后,忘记phpmyadmin的root密码,怎么办

    如果忘记MySQL root密码,如何重设密码?执行如下命令:wget http://soft.vpser.net/lnmp/ext/reset_mysql_root_password.sh;sh r ...

  6. 用LR12录制app,用LR11跑场景,无并发数限制,已试验过,可行!

    免费使用LoadRunner对移动互联网后端服务器压力测试 一.LoadRunner简介 LoadRunner,是惠普公司研发的一款预测系统行为和性能的负载测试工具.通过以模拟上千万用户实施并发负载及 ...

  7. 搭建openfire Android 客户端学习和开发【二】spark源码导入eclipse

    首先声明下 这是我在eoe上转载的 写的很好就摘抄了... 第一步 下载源码 svn下载,下载地址:spark:http://svn.igniterealtime.org/svn/repos/spar ...

  8. 在 OpenGL ES 2.0 上实现视差贴图(Parallax Mapping)

    在 OpenGL ES 2.0 上实现视差贴图(Parallax Mapping) 视差贴图 最近一直在研究如何在我的 iPad 2(只支持 OpenGL ES 2.0, 不支持 3.0) 上实现 视 ...

  9. 第3章 K近邻法

    参考: http://www.cnblogs.com/juefan/p/3807713.html http://blog.csdn.net/v_july_v/article/details/82036 ...

  10. myeclipse2014安装反编译插件

    一.在线安装方式: Eclipse Class Decompiler整合了目前最好的2个Java反编译工具Jad和JD-Core,并且和Eclipse Class Viewer无缝集成,能够很方便的使 ...