函数式语言(Erlang、F#、Haskell、Scala)

发布于 2024-07-18 07:52:58 字数 1431 浏览 9 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

一向肩并 2024-07-25 07:52:58

您描述的那种函数式语言是通用编程语言,它们用于各种事物,包括网络应用程序和商业应用程序。 (我使用哈斯克尔)。

正如 gabor 所暗示的那样,最终归结为库。 Scala 有一个 Web 框架:lift。 Haskell 有 happstack,以及 2100 4400(2010) 2012)Hackage 上的各种库。

当考虑特定的专业领域时,这实际上并不是语言的问题,而是工具链的问题。

Functional languages of the kind you describe are general purpose programming languages, they're used for all manner of things, including web apps and business apps. (I use Haskell).

As gabor implies, ultimately it comes down to libraries. Scala has a web framework: lift. Haskell has happstack, as well as 2100 4400 (in 2010 2012) libraries on Hackage for all manner of thiings.

It really isn't so much a question of the language, as the toolchain, when considering particular specialized domains.

手长情犹 2024-07-25 07:52:58

函数式语言适合任何您想要使用它们的用途。

然而,如今开发应用程序并不像使用编程语言那么简单。 Java、C# 等的优点是它们附带了构建业务软件时绝对需要的大型库和其他环境细节。 大多数函数式语言还没有那么强大的支持(到目前为止?)。

F# 可能很有前途,因为它位于 .NET 环境中,并且可以利用那里可用的工具(如果我错了,请纠正我)。

这篇文章介绍了如何使用 Lisp(一种早期函数式语言)成功创建基于 Web 的应用程序。

Functional languages are good for anything you would like to use them for.

However, developing applications these days are not as simple as using a programming language. The advantage of Java, C#, etc. is that they come with large libraries and other environment niceties that are absolutely required when you build business software. Most functional languages do not have that great support (as yet?).

F# might be promising since it's in the .NET environment and can take advantage of the tools available there (correct me if I'm wrong).

This article describes how Lisp, an early functional language, was used to create a web based application successfully.

杀手六號 2024-07-25 07:52:58

函数式语言非常适合 Web 应用程序开发,尤其是 Scala。

请查看 Lift 框架了解更多信息。

Functional languages are well suited for web application development, Scala in particular.

Have a look at the Lift framework for more information.

梦与时光遇 2024-07-25 07:52:58

2) 函数式语言适合商业/ERP/CRM 类型的应用程序吗?

为了解决有关业务/ERP/CRM 应用程序的第二点:就我个人而言,我不会使用像 Haskell 这样的“纯”函数式语言或像 Clojure 这样的动态函数式语言来实现这些应用程序。 另一方面,我目前正在 Scala 中实现 ERP,当然它是混合 OOP/FP 且静态编译的。

我这么说的原因是,像 ERP 这样的业务应用程序基本上是面向记录的:有一个表达不同记录类型的数据模式,然后应用程序逻辑几乎完全围绕 CRUD 这些记录并将自定义业务工作流程应用于它们而设计。 从根本上说,我不认为这类以数据为中心的业务应用程序非常适合功能模型。

人们可以随心所欲地谈论 OOP 关系不匹配,但最终 OOP 和数据库都是面向记录的:具有良好 ORM 的 OOP 语言可以让您将这些不同的数据模型映射到代码中,然后附加代码来处理每个数据模型。楷模。 拥有这种静态类型(最好使用像 Scala 的 squeryl 这样的强类型 ORM)可以大大减少出现运行时错误的可能性,或者例如对数据模型之一的更改未通过代码正确应用的可能性。

不要误会我的意思 - 我是 FP 的忠实粉丝(我越来越多地使用 Haskell 进行系统编程),但对我来说,面向记录的 OOP 方法比面向函数的方法更有意义FP 用于整理商业 ERP 或类似的数据对象。 (Scala 是这个规则的一个很好的例外,因为您可以使用 OOP 范式和高质量的 ORM 来进行记录操作,而且还可以使用 FP 的优点来进行一般的应用程序编程。)

2) Are functional languages suited for business/ERP/CRM type of applications?

To address the second point about business/ERP/CRM apps: personally I wouldn't implement these in a "pure" functional language like Haskell, or a dynamic functional language like Clojure. On the other hand, I am currently implementing an ERP in Scala, which of course is hybrid OOP/FP and statically compiled.

The reason I say this is that a business app like an ERP is fundamentally record-oriented: there is a data schema expressing the different record types and the app logic is then designed almost wholly around CRUDing those records and applying custom business workflows to them. And fundamentally, I don't believe that these sorts of data-centric business apps are a great fit for the functional model.

People can talk about the OOP-relational mismatch all they like but ultimately both OOP and databases are record-oriented: an OOP language with a good ORM lets you map those different data models into your code and then attach the code to handle each of the models. And having this statically typed (ideally with a strongly-typed ORM like Scala's squeryl) massively reduces the chances of a runtime error or e.g. a change to one of the data models not being properly applied through the code.

Don't get me wrong - I'm a big fan of FP (I'm doing more and more of my systems programming in Haskell), but for me the record-oriented approach of OOP makes more sense than the function-oriented approach of FP for wrangling the data objects of a business ERP or similar. (Scala is a nice exception to the rule because you get to use the OOP paradigm with quality ORMs for the record manipulation, but also the FP goodness for your general app programming.)

孤芳又自赏 2024-07-25 07:52:58
  1. 是的,Nitrogen 是功能性 Web 框架的一个很好的例子。 它也可以扩展。

http://nitrogenproject.com/

  1. Yes, Nitrogen is a good example of a functional web framework. It scales also.

http://nitrogenproject.com/

猫性小仙女 2024-07-25 07:52:58

Yaws 是 Erlang 的一个出色的 Web 服务器。

Yaws is a fantastic web server for Erlang.

娇女薄笑 2024-07-25 07:52:58

虽然我不会说任何特定的函数式语言都是为进行 Web 开发而定制的,但我也不会说您不能使用函数式语言进行 Web 开发。 我认为这完全取决于您选择的语言可以使用哪些 Web 框架以及是否有支持该语言的 Web 服务器。

例如,我确信您可以在 IIS 上使用 F# 和 ASP.Net 进行 Web 开发。 我怀疑模板引擎是否支持 F#,但您绝对可以用 F# 编写业务逻辑。

同样,Apache 有 mod_haskell,这应该使得使用 haskell 进行动态输出变得相对容易。 虽然,我个人从未使用过它。 同时,如果 Apache 有一个 mod_(erlang 或 scala),那么对于这些​​语言来说也会同样容易。

最终,我认为函数式语言的无状态本质应该使其非常适合无状态、MVC 风格的 Web 框架。 然而,我认为这实际上取决于哪些工具和框架可以让您在使用这些语言时变得更轻松。 例如,在 Rails 流行之前,Ruby 并没有真正流行于 Web 开发,而在我发现 django 之前,我并不真正喜欢用 Python 做任何 webby 的事情。

While I wouldn't say that any particular functional languages are tailored for doing web-development, I also wouldn't say that you can't do web development with a functional language. I think that depends entirely on what web frameworks may be available for the language you choose and whether or not there are any web servers that will support the language.

For instance, I'm sure that you can use F# along with ASP.Net on IIS to do web development. I doubt there's support for F# in the templating engine, but you can definitely write business logic in F#.

Similarly, there's mod_haskell for Apache, which should make it relatively easy to have dynamic output with haskell. Although, I've never personally used it. At the same time, if there's a mod_(erlang or scala) for Apache, it would be similarly easy for those languages.

Ultimately, I think that the stateless nature of functional languages should make it well suited for a stateless, MVC style web framework. However, I think it really comes down to what tools and frameworks are available to make your life easier when working with these languages. For example, Ruby wasn't really popular for web development until rails got popular, and I didn't really like doing anything webby with Python until I found django.

混浊又暗下来 2024-07-25 07:52:58

函数式语言提供了可用于 Web 开发的新型抽象。 例如,基于连续性的 Web 服务器在函数式语言中很流行。 PLT 方案 Web 服务器 支持此类 Web 应用程序开发。 您可以在 wikipedia 上了解有关延续及其在 Web 开发中的使用的更多信息

Functional languages provides new kinds of abstractions which can be used for web development. Continuation based web servers are for example popular among functional languages. The PLT Scheme web server supports this kind of web application development. You can read more about continuations and their use in web development on wikipedia

一身仙ぐ女味 2024-07-25 07:52:58

大多数函数式语言(即您所包含的语言)都被视为通用语言。 对于 Web 开发,我会深入考虑使用 Clojure 或 Scala。 它们都有非常好的 Web 框架,并且都运行在 JVM 上。 我完全可以推荐 Clojure 和 Scala,但不太推荐其他的。

Haskell有一个Web框架,但我从未使用过它。

商业应用? 当然,为什么不呢。 函数式语言几乎适用于任何事情。

Most functional languages, namely the ones you included, are considered general purpose languages. For web development, I would deeply consider using Clojure, or Scala. They both have very good web frameworks, and they both run on the JVM. I can totally recommend Clojure and Scala, but not so much for the others.

Haskell has a web framework, but I have never used it.

Business applications? Sure, why not. Functional languages are great for just about anything.

⒈起吃苦の倖褔 2024-07-25 07:52:58

函数式语言的支持者声称的最大优点之一是它们使编写可以并行执行的程序变得更容易。 但 Web 应用程序通常不存在并行性问题。 通常,Web 服务器/应用程序服务器维护一个线程池,每个用户请求都分配给不同的线程,该线程可以在不同的物理处理器上运行。 因此,您可以利用多个处理器而不会遇到太多麻烦。 诀窍在于,网络应用程序的特点是存在大量小请求,而线程和命令式语言在那里可以很好地工作。 当您有少量计算成本较高的请求时,命令式语言开始崩溃。

函数式语言的另一大优点是,由于函数没有副作用,因此测试更容易。 您通过几个输入单独测试每个功能,并且您知道系统将正常工作。 但是,有一个问题。 如果您的操作涉及输入或输出,则您使用 monad 而不是函数,并且您将失去该部分代码的可测试性优势。

但是,通常 Web 应用程序涉及从请求中读取信息、向数据库发出请求、从数据库中读取响应以及格式化响应。 这是大量的 IO 或 monad,而函数的机会却很少。

鉴于Web应用程序的这些特征,函数式语言给Web应用程序编程带来了哪些好处?

One of the biggest advantages claimed by proponents of functional languages is that they make it easier to write programs that can execute in parallel. But web applications typically don't have problems with parallelism. Typically, the web server/application server maintains a pool of threads, and each user request is assigned to a different thread, which can run on a different physical processor. So, you can take advantage of multiple processors without too much trouble. The trick is that web apps are characterized by large numbers of small requests, and threads and imperative languages work well there. Where imperative languages start to break down is when you have a small number of computationally expensive requests.

Another big advantage of functional languages is that since functions have no side effects, testing is easier. You test each function in isolation across a few of its inputs, and you know the system will work. But, there's a catch. If your operation involves input or output, you use a monad rather than a function, and you lose this testability benefit for that portion of your code.

But, typically web applications involve reading information from a request, making requests to a database, reading the response from the database, and formatting a response. That's lots and lots of IO, or monads, and very little opportunity for functions.

Given these characteristics of web applications, what benefits do functional languages bring to web application programming?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文