[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 ...
随机推荐
- TCP三次握手,什么情况下client会回复reset
1. 现象 最近线上发现如下异常包, tcp三次握手期间,server端发送syn_ack,client回复了reset包: 问题:为什么client会回复reset? 2. 分析 参考linux2. ...
- Redis学习篇(十二)之管道技术
通过管道技术降低往返时延 当后一条命令不依赖于前一条命令的返回结果时,可以使用管道技术将多条命令一起 发送给redis服务器,服务器执行结束之后,一起返回结果,降低了通信频度.
- Eigen学习笔记1:在VS2015下Eigen(矩阵变换)的配置
一.Eigen简介 Eigen是一个高层次的C ++库,有效支持线性代数,矩阵和矢量运算,数值分析及其相关的算法. Eigen适用范围广,支持包括固定大小.任意大小的所有矩阵操作,甚至是稀疏矩阵:支持 ...
- [CODECHEF]EASYEX
题意:有一个$k$面的骰子,上面的数字为$1\cdots k$,现在要丢$n$次骰子,设$n$次中有$a_i$次扔到数字$i$,给定$l,f$,求$\prod\limits_{i=1}^la_i^f$ ...
- 2015 UESTC 搜索专题M题 Palindromic String 马拉车算法
Palindromic String Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/s ...
- 如何判断c语言的变量类型
变量三要素: 一个变量有三个基本的要素,变量的名称,变量的类型,变量的值.所以int a = 10; 变量名为a,变量的存储类型为int型,变量的值为10. 变量还有一些属性如作用范围和存储类型. 变 ...
- Ubantu14.04下编译OpenCV3.0.0以及读取图片例子
以前一直使用opencv 2.x的版本,现在3.0的已经发布成正式版了,尝试在Linux下安装. 收集了一篇不错的经验教程: Ubuntu14.04下安装OpenCV3.0经验. 编译的过程大概需要3 ...
- Python类中self的作用
摘自论坛: self:是指向你新创建对象实例的引用,在这个地方指向你创建的Person类的实例p.当你调用Person类创建实例时,self指的就是你这个P,所以这个地方p=Person('tiany ...
- PHP大转盘中奖概率算法实例
本文实例讲述了PHP大转盘中奖概率算法的实现方法,分享给大家供大家参考.具体如下: 大转盘是最近很多线上网动中一个比较有意思的东西了,下面我们就来看看这个大转盘中奖概率算法与例子,希望对各位有所帮助. ...
- busdog is a filter driver for MS Windows (XP and above) to sniff USB traffic.
https://code.google.com/p/busdog/ busdog is a filter driver for MS Windows (XP and above) to sniff U ...