[Functional Programming] Function signature
It is really important to understand function signature in functional programming.
The the code example below:
const map = fn => anyFunctor => anyFunctor.map(fn);
'map' is pointfree version of any founctor's map, for example:
Maybe.of('maybe').map(toUpper)
equals:
compose(map(toUpper), Maybe.of)('maybe') // Just 'MAYBE'
So what is the function signature for 'map'?
fn: is a function, we can use
(a -> b) : We read it as "A function which take a to b"
anyFunctor: is a Functor, any Functor, we can use:
f a: here 'f' means Functor, 'a' means 'any value': We read it as 'Any functor a'
anyFunctor.map(fn): is what the return value, it is also a Functor, value may different from 'a':
f b: here 'f' means Functor, 'b' means 'any value but not the same as 'a' '.
Here we want to point out 'f' is Functor, we can do: 'Functor f =>'
// map :: Functor f => (a -> b) -> f a -> f b
This is the whole result:
// map :: Functor f => (a -> b) -> f a -> f b
const map = fn => anyFunctor => anyFunctor.map(fn);
[Functional Programming] Function signature的更多相关文章
- Functional programming idiom
A functional programming function is like a mathematical function, which produces an output that typ ...
- 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 1 Functional Composition
Functions in Java Prior to the introduction of Lambda Expressions feature in version 8, Java had lon ...
- Functional Programming without Lambda - Part 2 Lifting, Functor, Monad
Lifting Now, let's review map from another perspective. map :: (T -> R) -> [T] -> [R] accep ...
- 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)
初学函数式编程,相信很多程序员兄弟们对于这个名字熟悉又陌生.函数,对于程序员来说并不陌生,编程对于程序员来说也并不陌生,但是函数式编程语言(Functional Programming languag ...
- BETTER SUPPORT FOR FUNCTIONAL PROGRAMMING IN ANGULAR 2
In this blog post I will talk about the changes coming in Angular 2 that will improve its support fo ...
随机推荐
- 【拓扑排序或差分约束】Guess UVALive - 4255
题目链接:https://cn.vjudge.net/contest/209473#problem/B 题目大意:对于n个数字,给出sum[j]-sum[i](sum表示前缀和)的符号(正负零),求一 ...
- Visitor设计模式
我猜想许多人都知道访问者设计模式,这种模式在“四人帮”的那本可复用面向对象软件基础的书被描述过.这个模式自身其实一点也不复杂(和以往的其他设计模式一样). 如上图所示: 我知道这个模式很久了,但是我 ...
- 基于NMAP日志文件的暴力破解工具BruteSpray
基于NMAP日志文件的暴力破解工具BruteSpray 使用NMAP的-sV选项进行扫描,可以识别目标主机的端口对应的服务.用户可以针对这些服务进行认证爆破.为了方便渗透测试人员使用,Kali L ...
- 检验Xcode是否被改动过的简单方法,不妨试试!!!
检验Xcode是否被改动过的简单方法,不妨试试!!! 在终端系统上运行以下命令启用检测: spctl --assess --verbose /Applications/Xcode.app ...
- Hibernate 条件-分页查询
这里我们继续跟着上一次的节奏继续学习Hibernate的查询. 1.条件查询一(占位符) 按照占位符的方式进行条件查询,这里query有一个setInteger(arg1, arg2)方法,其中第一个 ...
- mui实现列表的下拉刷新上拉加载
1.引入mui控件的js文件和css样式文件 <link rel="stylesheet" href="css/mui.min.css"> < ...
- codevs 1226 倒水问题
1226 倒水问题 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 有两个无刻度标志的水壶,分别可装 x 升和 y 升 ( x, ...
- [COGS2427][HZOI 2016]seq
[COGS2427][HZOI 2016]seq 题目大意: 一个长度为\(n(n\le10^6)\)的序列,\(q(q\le10^6)\)次操作,每次将所有\(a\)变成\(b\),求最后的序列. ...
- PIL The _imaging C module is not installed
今天在WIN 7 64位用PIL的时候,提示 The _imaging C module is not installed ,原来是需要安装64位的. 刚开始安装的是这个:http://www.pyt ...
- Codeforces Beta Round #7 D. Palindrome Degree hash
D. Palindrome Degree 题目连接: http://www.codeforces.com/contest/7/problem/D Description String s of len ...