[Functional Programming] Church Encodings: Numberals
const log = console.log; // zero :: &fa.a
const zero = f => x => x; // zero is F
// once :: &fa.fa
const once = f => x => f(x); // once it I
// twice :: &fa.f(fa)
const twice = f => x => f(f(x));
// thrice :: &fa.f(f(fa))
const thrice = f => x => f(f(f(x))); const T = true;
const F = false;
const I = x => x;
const not = x => !x; log(zero(not)(T)) // true, because only return second arguement
log(once(not)(T)) // false
log(twice(not)(F)) // false
log(thrice(not)(T)) // false log('****') /** SUCCSOR
SUCC N1 = N2
SUCC N2 = N3
SUCC(SUCC N1) = N3 SUCC &fa.fa = &fa.f(fa)
SUCC N2, then n is 2, do f n times, then add one f more
*/
const succ = n => f => x => f(n(f)(x));
// conver chunch number to JS number.
// jsnum :: take a chunch number, call (x => x + 1) n times, and start from 0.
const jsnum = n => n(x => x + 1)(0);
log(succ(zero)(not)(T)) // false
log(jsnum(succ(zero))) // 1
log(jsnum(succ(succ(zero)))) // 2 const n0 = zero;
const n1 = once;
const n2 = twice;
const n3 = thrice;
const n4 = succ(thrice); log(jsnum(succ(n2))) // 3
[Functional Programming] Church Encodings: Numberals的更多相关文章
- Beginning Scala study note(4) Functional Programming in Scala
1. Functional programming treats computation as the evaluation of mathematical and avoids state and ...
- Functional Programming without Lambda - Part 2 Lifting, Functor, Monad
Lifting Now, let's review map from another perspective. map :: (T -> R) -> [T] -> [R] accep ...
- Functional Programming without Lambda - Part 1 Functional Composition
Functions in Java Prior to the introduction of Lambda Expressions feature in version 8, Java had lon ...
- a primary example for Functional programming in javascript
background In pursuit of a real-world application, let’s say we need an e-commerce web applicationfo ...
- Functional programming
In computer science, functional programming is a programming paradigm, a style of building the struc ...
- Java 中的函数式编程(Functional Programming):Lambda 初识
Java 8 发布带来的一个主要特性就是对函数式编程的支持. 而 Lambda 表达式就是一个新的并且很重要的一个概念. 它提供了一个简单并且很简洁的编码方式. 首先从几个简单的 Lambda 表达式 ...
- Functional programming idiom
A functional programming function is like a mathematical function, which produces an output that typ ...
- 关于函数式编程(Functional Programming)
初学函数式编程,相信很多程序员兄弟们对于这个名字熟悉又陌生.函数,对于程序员来说并不陌生,编程对于程序员来说也并不陌生,但是函数式编程语言(Functional Programming languag ...
- Functional Programming 资料收集
书籍: Functional Programming for Java Developers SICP(Structure and Interpretation of Computer Program ...
随机推荐
- [转帖]云服务器使用CentOS、Debian、Ubuntu的哪个版本
云服务器使用CentOS.Debian.Ubuntu的哪个版本 2018-09-09 12:32:45作者:ywnz稿源:云网牛站 https://ywnz.com/linuxyffq/2986.ht ...
- Oracle-DQL 4- 多表查询
多表查询: 1.笛卡尔积SELECT * FROM dept;--查询员工的信息和其所在部门的信息SELECT ename,job,dname,locFROM emp,dept; --集合A中的所有元 ...
- Java时间处理
java.sql.PreparedStatement接口的setDate(int parameterIndex, java.sql.Date x)方法中的Date为java.sql包下的Date,而不 ...
- 用SPFA 解决POJ2240
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30790 Accepted: 12761 Descr ...
- Python库的优雅安装及PyCharm虚拟环境配置
一.安装python库 安装python库有几种方式: 1. 使用pip命令行,如:pip install Pillow 2. 在pycharm中安装 3. 使用Anaconda批量安装常用模块 在使 ...
- 计算广告CTR预估系列(七)--Facebook经典模型LR+GBDT理论与实践
计算广告CTR预估系列(七)--Facebook经典模型LR+GBDT理论与实践 2018年06月13日 16:38:11 轻春 阅读数 6004更多 分类专栏: 机器学习 机器学习荐货情报局 版 ...
- servlet容器,web容器,spring容器,springmvc容器的区别(转)
web容器中有servlet容器,spring项目部署后存在spring容器和springmvc容器.其中spring控制service层和dao层的bean对象.springmvc容器控制contr ...
- 怎样理解Node对象接口
dom中的节点都继承自Node接口, 也就是说, 所有的节点都具有Node接口所规定的属性和方法, 比如下面这个 <a> 标签, 它也继承了Node的所有属性和方法: 可以认为Node接口 ...
- 移动站Web开发图片自适应两种常见情况解决方案
本文主要说的是Web中图片根据手机屏幕大小自适应居中显示,图片自适应两种常见情况解决方案.开始吧 在做配合手机客户端的Web wap页面时,发现文章对图片显示的需求有两种特别重要的情况,一是对于图集, ...
- dev gridview拖拽数据移动
设置属性gridView1.OptionsSelection.EnableAppearanceFocusedCell = false; //确保选定行的背景色一样. private BindingLi ...