[PureScript] Basic Data Constructors in PureScript
PureScript types are very extensive and we are going to experiment with type constructors and how to make then use them.
We can define a custom data type:
-- Data constructors
data FooType = Foo | Bar String
Define a function, take FooType, return a string:
runFoo :: FooType -> String
-- runFoo take a param Foo which should be string
runFoo Foo = "it is foo"
-- runFoo also can take Bar and String
-- <> is similar to str.concat isn JS
runFoo (Bar s) = "Yeah it's Bar and " <> s
Because FooType is Unit type, we need to define both 'Foo' and '(Bar s)'.
main = render =<< withConsole do
log $ show $ runFoo (Bar "Wan") -- "Yeah it's Bar and Wan"
log $ show $ runFoo Foo -- "it is foo"
--
FullCode:
module Main where import Prelude
import Control.Monad.Eff.Console (log)
import TryPureScript myTypes :: Int
myTypes = 1 -- add (a -> (b -> (a + b)))
add :: Int -> Int -> Int
add a b = a + b
addMe = \a -> \b -> a + b -- inc (a -> (add 1 a))
inc :: Int -> Int
inc = add 1 -- Data constructors
data FooType = Foo | Bar String runFoo :: FooType -> String
-- runFoo take a param Foo which should be string
runFoo Foo = "it is foo"
-- runFoo also can take Bar and String
-- <> is similar to str.concat isn JS
runFoo (Bar s) = "Yeah it's Bar and " <> s main = render =<< withConsole do
log $ show $ runFoo (Bar "Wan") -- "Yeah it's Bar and Wan"
log $ show $ runFoo Foo -- "it is foo"
[PureScript] Basic Data Constructors in PureScript的更多相关文章
- hdu-5929 Basic Data Structure(双端队列+模拟)
题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- HDU 5929 Basic Data Structure 模拟
Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- HDU 5929 Basic Data Structure 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- Basic Data Structure
Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- Basic Data Structure HDU - 5929 (这个模拟我要报警了)
Mr. Frog learned a basic data structure recently, which is called stack.There are some basic operati ...
- [OpenCV] Basic data types - Matrix
http://docs.opencv.org/2.4.13/ Basis 矩形 "modules/core/src/drawing.cpp" CV_IMPL void cvRect ...
- 1.6 Indexing and Basic Data Operations--目录
1.6.1 什么是 Indexing 1.6.2 Uploading Data with Index Handlers 1.6.3 Uploading Data with Solr Cell usin ...
- Basic Data Structures and Algorithms in the Linux Kernel--reference
http://luisbg.blogalia.com/historias/74062 Thanks to Vijay D'Silva's brilliant answer in cstheory.st ...
- Chapter 04—Basic Data Management
1. 创建新的变量 variable<-expression expression:包含一组大量的操作符和函数.常用的算术操作符如下表: 例1:根据已知变量,创建新变量的三种途径 > my ...
随机推荐
- .yaml 文件格式简介
命名 YAML 的意思其实是:"Yet Another Markup Language"(仍是一种置标语言)的缩写. 功能 YAML的语法和其他高阶语言类似,并且可以简单表达清单. ...
- Programming 2D Games 读书笔记(第四章)
示例一:Game Engine Part 1 更加完善游戏的基本流程 Graphics添加了以下几个方法,beginScene和endScene提高绘图,showBackbuffer去掉了clea ...
- 【教程】新手如何制作简单MAD和AMV,学不会那都是时辰
[教程]新手如何制作简单MAD和AMV,学不会那都是时 http://tieba.baidu.com/p/2303522172 [菜鸟教你做MAD]Vegas制作MAD入门教程 http://tieb ...
- Java基础加强总结(三)——代理(Proxy)
一.代理的概念 动态代理技术是整个java技术中最重要的一个技术,它是学习java框架的基础,不会动态代理技术,那么在学习Spring这些框架时是学不明白的. 动态代理技术就是用来产生一个对象的代理对 ...
- 对数据集“dsArea”执行查询失败。 (rsErrorExecutingCommand),Query execution failed for dataset 'dsArea'. (rsErrorExecutingCommand),Manually process the TFS data warehouse and analysis services cube
错误提示: 处理报表时出错. (rsProcessingAborted)对数据集“dsArea”执行查询失败. (rsErrorExecutingCommand)Team System 多维数据集或者 ...
- EEPLAT学习
eeplat:Open Source Metadata PaaS 開始学习的时候仅仅是下了整个项目而且跑通,顺手在这个平台自己主动化的建立 了个管理系统,接下来開始深入研究这个开源平台 所谓元数据(m ...
- firedac数据集和字符串之间相互转换
firedac数据集和字符串之间相互转换 /// <author>cxg 2018-12-20</author> unit DatasetString; interface u ...
- 开源项目PullToRefresh详解(四)——PullToRefreshListView和ViewPager的结合使用
其实这个不是什么新东西了,在介绍(一)中我们就知道了PullToRefreshListView的用法,这里只要将其放入到ViewPager中就行啦.ViewPager还是和以往一样的定义和使用,在适配 ...
- JAVA生成并导出json文件
将一个list集合转换成json文件并导出: 数据集合: List<Object> agencyList = new ArrayList<Object>(); Map<S ...
- ubuntu修改软链接
https://blog.csdn.net/u012897374/article/details/79199336 添加软连接(symbol link)相当于添加一个快捷方式,解决cannot ope ...