[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 ...
随机推荐
- HDU 4731 Minimum palindrome (2013成都网络赛,找规律构造)
Minimum palindrome Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- LPC43XX TQFP144 IO Pinout
- How to properly set clock speed for STM32F4xx devices
http://stm32f4-discovery.com/2015/01/properly-set-clock-speed-stm32f4xx-devices/ I see that you have ...
- 修復 “Failed to bring up eth0″ in Ubuntu virtualbox
参考文献: 修復 “Failed to bring up eth0″ in Ubuntu VMWare ubuntu下smokeping安装配置 背景 从同事那边拷贝了一个virtualbox虚拟机过 ...
- SQL Server、Oracle和MySQL中查出值为NULL的替换
参考文献: http://database.51cto.com/art/200803/67397.htm 正文 在SQL Server Oracle MySQL当数据库中查出某值为NULL怎么办? 1 ...
- ICO如此疯狂为哪般?
编者语: 独角兽一词起源于硅谷,是投资行业,尤其是风险投资业的术语,指的是那些估值超过十亿美元的创业公司.独角兽凤毛麟角,占创业公司总数的0.1%都不到.鑫根资本认为,一个独角兽能达到如此估值,肯定是 ...
- Embarcadero RAD Studio XE5
英巴卡迪诺 RAD Studio XE是终极应用程序开发套件,能以最快速方式为Windows.Mac OS X. .NET. PHP. Web和移动设备可视化开发数据丰富.界面美观的跨平台应用程序.R ...
- WCF技术我们应该如何以正确的方式去学习掌握
一.WCF技术我该如何学习? 阿笨的回答是:作为初学者的我们,那么请跟着阿笨一起玩WCF吧,阿笨将带领大家如何以正确的姿势去掌握WCF技术.由于WCF技术知识点太多了,就纯基础概念性知识都可以单独出一 ...
- delphi ribbon使用
http://blog.csdn.net/davinciyxw/article/details/5604209 1.TextEditor(barEditItem)取文本 string editValu ...
- 如何在Windows服务程序中添加U盘插拔的消息
研究了下这个问题,主要要在一般的windows服务程序中修改两个地方: 一.调用RegisterServiceCtrlHandlerEx VOID WINAPI SvcMain( DWORD dwAr ...