惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - greater

Matlab 7.0不断重启问题解决方法 安装Matlab过程中遇到拒绝访问怎么办? NUnit图解(一) [翻译]Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition 第二十四章 LINQ API编程(三) [翻译]Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition 第二十四章 LINQ API编程(二) [翻译]Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition 第二十四章 LINQ API编程(一) 迷人舞步 难译的英文单词 Linq 之Expression Tree再思考 VS2008代码段快捷方式小记 Linq To SQL分页失败后引发的思考 Linq之查询非泛型集合 Linq操作符之筛选特定位置的元素 Linq与斐波那契数列共舞 Linq的那些事——从Linq扩展方法回顾C#语言基础 Linq To Object实例之过滤字符集 Linq之C#3.0语言扩展 Linq to DataSet 之Access查询 从101 LINQ Samples开始
函数式编程的浅议
greater · 2008-06-17 · via 博客园 - greater

先来看看一段来自于IBM的说法

函数式编程只描述在程序输入上执行的操作,不必使用临时变量保存中间结果。重点是捕捉 “是什么以及为什么”,而不是 “如何做”。与将重点放在执行连续命令上的过程性编程相比,函数式编程的重点是函数的定义而不是状态机(state machine)的实现。大型知识管理系统应用程序从使用函数式编程风格上受益颇多,因为函数式编程简化了开发。

下面从C#的lambda入手看看如何理解比较简单
而第二个函数就是Y组合子的定义模式:

let Y = lambda y . (lambda x . y (x x)) (lambda x . y (x x))
Y=(\f(\x.f(x x))(\x.f(x x)))

static Func<T,TResult>Y<T,TResult>(Func<T,TResult> F)
{
    
return F;
}

static Func<T,TResult> Y2<T, TResult>(Func<Func<T, TResult>, Func<T,TResult>> F)
{
    
return (x)=>F(Y2(F))(x);
}

第一个函数的参数是一个以Func<T,TResult>为类型的函数,由于F的最终值为TResult类型所以符合要求。
第二个函数的参数是一个以Func<Func<T, TResult>, Func<T,TResult>> 为类型的函数F,它是如何实现函数调用的呢?
1.Func<Func<T, TResult>, Func<T,TResult>> 中的第一个参数Func<T, TResult>,定义的是一个参数的输入类型这和Y2的类型相匹配,而且由于第二个Func<T, TResult>参数定义的是她的返回类型与Y2的返回类型相匹配所以参数定义正确
2.返回值中(x)=>F(Y2(F))(x);由外到里可以看到F和Y2都是以<T, TResult>为参数模式来定义的所以多重调用并不会影响其实际的结果。即x;
3.调用上来说 Console.WriteLine(Y2<int, int>(add=>x=>x+3)(3));中实际上就是Y2函数的两次调用。从=>和Y2参数的Func匹配次数就可见一般。