到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. html标签页图标

    在head标签加入如下内容: <!--可以在收藏夹中显示出图标--> <link rel="Bookmark" type="image/png" ...

  2. Linux之Sed命令详解(总结一些实用例子)

    简介 sed 是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的 ...

  3. C# Socket大文件上传

    public sealed class SocketData { private SocketData() { } public static SendFileMode SendFile(Socket ...

  4. 查看域名对应的ip地址

    nslookup   www.google.com.hk

  5. 【原创】ui.router源码解析

    Angular系列文章之angular路由 路由(route),几乎所有的MVC(VM)框架都应该具有的特性,因为它是前端构建单页面应用(SPA)必不可少的组成部分. 那么,对于angular而言,它 ...

  6. 如何更改firefox默认搜索引擎?一步搞定!

    由于开发设计的需要,ytkah平时习惯使用firefox作为默认浏览器,火狐浏览器可添加的扩展功能比较,比如firebug.nofollow.seoquake等,还有比较友好的功能就是选中关键词拖动直 ...

  7. vim显示行号

    在Linux环境下的编辑器有vi.vim.gedit等等.进入这些编辑器之后,为了方便我们需要编辑器显示出当前的行号,可偏偏编辑器默认是不会显示行号的.我们有二种办法可以解决: 第一种是,手动显示:在 ...

  8. characterCustomezition的资源打包代码分析

    using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; class Creat ...

  9. [官方教程] [ES4封装教程]1.使用 VMware Player 创建适合封装的虚拟机

    [转载处,http://bbs.itiankong.com/] 前言: 首先要明确的一点,系统封装操作的源计算机一般为虚拟计算机(简称虚拟机.VM等),这也是为什么我们要在封装教程的第一章就专门学习虚 ...

  10. 每天一个linux命令day2【ss命令】

    ss是Socket Statistics的缩写.顾名思义,ss命令可以用来获取socket统计信息,它可以显示和netstat类似的内容.但ss的优势在于它能够显示更多更详细的有关TCP和连接状态的信 ...