[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 ...
随机推荐
- 从JDBC看Mybatis的设计
Java数据库连接,(Java Database Connectivity,简称JDBC)是Java语言中用来规范客户端程序如何来访问数据库的应用程序接口,提供了诸如查询和更新数据库中数据的方法. 六 ...
- 5分钟掌握智联招聘网站爬取并保存到MongoDB数据库
前言 本次主题分两篇文章来介绍: 一.数据采集 二.数据分析 第一篇先来介绍数据采集,即用python爬取网站数据. 1 运行环境和python库 先说下运行环境: python3.5 windows ...
- Python中的模块(2)
1.内置模块2.扩展的 例如:django3.自定义的 文件import demodef read(): print('my read func')demo.read()print(demo.mone ...
- functools.wraps 带参数的装饰器 多个装饰器装饰同一个函数
装饰器开发原则 : 开放封闭原则装饰器的作用 :在不改变原函数的调用方式的情况下,在函数的前后添加功能装饰器的本质 : 闭包函数 def wrapper(func): def inner(*args, ...
- EventBus机制 handler 区别
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 事件巴士 是 采用 观察者模式 实现 事件订阅总线, 可以用在 应用程序中, 组件之间, ...
- 使用辗转相除法求两个数的最大公因数(python实现)
数学背景: 整除的定义: 任给两个整数a,b,其中b≠0,如果存在一个整数q使得等式 a = bq 成立,我们就说是b整除 ...
- Ubantu14.04下编译OpenCV3.0.0以及读取图片例子
以前一直使用opencv 2.x的版本,现在3.0的已经发布成正式版了,尝试在Linux下安装. 收集了一篇不错的经验教程: Ubuntu14.04下安装OpenCV3.0经验. 编译的过程大概需要3 ...
- 客户端获取ip
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Java容器-引用分类与部分Map用法
目录 1.引用分类 2.了解WeakHashMap.IdentityHashMap.EnumMap 3.同步控制与只读设置 代码实现 1.引用分类(面试) 强引用(StrongReference):引 ...
- js——引用类型和基本类型
js中的数据类型有以下几种: 基本类型:Number Boolean String undefined null Symbol 引用类型:Object(Array, Function, Date ...