是F#真的比C#更好地为数学吗? [英] Is F# really better than C# for math?

查看:86
本文介绍了是F#真的比C#更好地为数学吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非托管语言尽管如此,是F#真的比C#更好地为实现数学吗?如果是这样的话,为什么?

Unmanaged languages notwithstanding, is F# really better than C# for implementing math? And if that's the case, why?

推荐答案

我觉得最重要的点,别人都已经提到:

I think most of the important points were already mentioned by someone else:


  1. F#,您可以解决的方式数学家思考他们的问题

  2. 由于高阶函数,可以用简单的概念来解决疑难问题

  3. 一切是默认不可改变的,这使得程序更容易理解(也更容易并行)

这肯定是真的,你可以使用一些F#的概念在C#3.0,但也有局限性。你可以不使用任何递归计算(因为C#不具备尾递归),这就是你如何写功能/数学方法计算原始。此外,在C#编写复杂的高阶函数(即采取其他功能参数)是困难的,因为你必须明确地写类型(而在F#中,类型推断,也自动一概而论,所以你不必明确地使函数通用)。

It is definitely true that you can use some of the F# concepts in C# 3.0, but there are limitations. You cannot use any recursive computations (because C# doesn't have tail-recursion) and this is how you write primitive computations in functional/mathematical way. Also, writing complex higher order functions (that take other functions as arguments) in C# is difficult, because you have to write types explicitly (while in F#, types are inferred, but also automatically generalized, so you don't have to explicitly make a function generic).

另外,我想从马克Gravell以下点不是一个有效的异议:

Also, I think the following point from Marc Gravell isn't a valid objection:

,我认为适当命名的属性等比元组和头部/尾列表更容易使用(在整个生命周期)的观点,但是这可能只是我的。

From a maintenance angle, I'm of the view that suitably named properties etc are easier to use (over full life-cycle) than tuples and head/tail lists, but that might just be me.

这当然是真的。然而,关于F#的伟大的事情是,你可以开始编写使用元组和放大器方案;头/尾名单和以后的发展过程中把它变成一个使用.NET IEnumerables和类型与性质的程序(这就是我认为典型的F#程序员的工作*)。元组等,以及F#互动发展工具使您能够快速原型解决方案的好方法(和做一些数学的时候,这是至关重要的,因为大部分的开发仅仅是试验,当你正在寻找最佳的解决方案)。一旦你的原型,可以用简单的源$ C ​​$ C转换包裹code inisde的F#类型(也可以从C#作为一个普通类)。 F#还为您提供了很多办法后,优化了code在性能方面。

This is of course true. However, the great thing about F# is that you can start writing the program using tuples & head/tail lists and later in the development process turn it into a program that uses .NET IEnumerables and types with properties (and that's how I believe typical F# programmer works*). Tuples etc. and F# interactive development tools give you a great way to quickly prototype solutions (and when doing something mathematical, this is essential because most of the development is just experimenting when you're looking for the best solution). Once you have the prototype, you can use simple source code transformations to wrap the code inisde an F# type (which can also be used from C# as an ordinary class). F# also gives you a lot of ways to optimize the code later in terms of performance.

这为您提供了易于使用的汉语语言(例如Python)的,许多人使用原型阶段的好处。不过,你不必重写后,一旦你与原型采用高效的语言完成整个程序(如C ++或者C#),因为F#是既简单易用和高效,你能流利地切换这两种风格之间。

This gives you the benefits of easy to use langauges (e.g. Python), which many people use for prototyping phase. However, you don't have to rewrite the whole program later once you're done with prototyping using an efficient language (e.g. C++ or perhaps C#), because F# is both "easy to use" and "efficient" and you can fluently switch between these two styles.

(*)我也用这种风格在我的函数式编程的书

(*) I also use this style in my functional programming book.

这篇关于是F#真的比C#更好地为数学吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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