Haskell和LINQ之间有任何联系吗? [英] Are there any connections between Haskell and LINQ?

查看:95
本文介绍了Haskell和LINQ之间有任何联系吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用LINQ在C#中编写了一些查询。过了一段时间,我开始使用Haskell,它是一种函数式编程语言(一种不太流行的语言),对我来说,它们似乎都是几乎相同的东西。但我不确定这一点。请问,如果有人比我更多地使用它们,他们能否告诉我他们在编程原则方面是否差不多?

此外,LINQ可以被视为函数式编程吗?



谢谢。

解决方案


对我来说,它们似乎都是几乎相同的东西。但我不确定这一点。请问,如果有人比我更多地使用它们,他们能否告诉我他们在编程原则方面是否差不多?

是的,LINQ查询解析的设计深受Haskell设计的影响。当我们设计LINQ时,Haskell专家Erik Meijer在C#语言设计委员会工作;他的见解非常有价值。 (我在这个过程结束时加入了设计团队,所以很遗憾,我没有参与所有有趣的曲折,多年来设计经历了一段时间;它开始比传统的面向对象更加复杂!)



如果您最近对Haskell进行了认真的探索,那么您可能已经熟悉Monad的想法。 LINQ语法专门用于使序列monad上的操作感觉自然,但实际上实现更一般; C#所谓的SelectMany是对任意monad上的绑定操作稍作修改的形式。您实际上可以使用任何monad的查询理解,正如我的同事Wes在这里所描述的那样,但是这样做看起来很奇怪,我建议在生产代码中反对它。


另外,LINQ可以被认为是函数式编程吗?


是的,LINQ深受函数式编程思想的影响。它被设计为将功能视为第一类对象,强调对副作用的计算等等。


I wrote some queries in C# using LINQ. After a while, I started using Haskell a little bit, which is a functional programming language (a not so popular one), and for me it seems that both of them are almost the same thing. But I am unsure about this. Please, if someone has used them more than me, could they tell me if they are almost the same thing regarding principles in programming ?

Also, could LINQ be considered functional programming ?

Thanks.

解决方案

for me it seems that both of them are almost the same thing. But I am unsure about this. Please, if someone has used them more than me, could they tell me if they are almost the same thing regarding principles in programming ?

Yes, the design of LINQ query comprehensions was heavily influenced by the design of Haskell. Haskell expert Erik Meijer was on the C# language design committee when we designed LINQ; his insights were very valuable. (I joined the design team at the end of this process, so unfortunately I did not get to participate in all the interesting twists and turns the design went through over the years; it started being much more traditional OO than it ended up!)

If you've recently done a serious exploration into Haskell then you're probably becoming familiar with the idea of a monad. The LINQ syntax is designed specifically to make operations on the sequence monad feel natural, but in fact the implementation is more general; what C# calls "SelectMany" is a slightly modified form of the "Bind" operation on an arbitrary monad. You can actually use query comprehension with any monad, as my colleague Wes describes here, but doing so looks pretty weird and I recommend against it in production code.

Also, could LINQ be considered functional programming ?

Yes, LINQ is heavily influenced by ideas from functional programming. It is designed to treat functions as first-class objects, to emphasize calculation over side effects, and so on.

这篇关于Haskell和LINQ之间有任何联系吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆