到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. Matalab IFS分形算法

    IFS 算法代码 function IFS_draw(M,p) N=; :length(p); eval(['a',num2str(k),'=reshape(M(',num2str(k),',:),2 ...

  2. PHP中的替代语法(转)

    我们经常在wordpress一类博客程序的模板里面看到很多奇怪的PHP语法,比如: <?php if(empty($GET_['a'])): ?> <font color=" ...

  3. wordpress编辑主题时报错Warning: scandir() has been disabled for security reasons in

    在ubuntu下面安装了一个wordpress程序,在后台什么都没干,编辑主题时,发现页面中报下面的错误. notice: /home/wwwroot/test.localhost/wordpress ...

  4. CF440C

    C. One-Based Arithmetic time limit per test 0.5 seconds memory limit per test 256 megabytes input st ...

  5. sql复制数据表和表结构

    SQL复制数据表 (select * into 与 insert into) select * into 目标表名 from 源表名 insert into 目标表名(fld1, fld2) sele ...

  6. SQL Server2008ldf文件太大

    --适用于SQL Server 2008的方法 USE [master] GO ALTER DATABASE RmyyHisDW SET RECOVERY SIMPLE WITH NO_WAIT GO ...

  7. easyui 删除行bug

    easyui删除行,出现了bug.(经常使用这个框架的人几乎都会遇到) 我也非常纳闷,今天特地试了很久. 最后发现,如果是自己datagrid('getRows') 然后迭代出来,最后算出行号,可以成 ...

  8. Step

    php+MySQL html+css JQuery Mobile JavaScript weiPHP Sina Cloud 微信公众订阅号平台开发

  9. webservice远程调试开启

    在.NET 中已经默认将WEBSERVICE的远程调试功能关闭,有的时候我们需要远程调试程序的时候,就需要打开此功能我们只需在WEBSERVICE的项目的中添web.config的<system ...

  10. 《ASP.NET1200例》实现投票的用户控件

    用户控件ascx <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="24 ...