简体   繁体   English

为什么ML语言(F#)与C语言(C#)相比有这么多不同的运算符?

[英]Why do ML languages (F#) have so many different operators compared to C languages (C#)?

It looks like it has several times more operators: 看来它的运算符多了几倍

https://msdn.microsoft.com/en-us/library/dd233228.aspx https://msdn.microsoft.com/zh-CN/library/dd233228.aspx

vs

https://msdn.microsoft.com/en-us/library/6a71f45d.aspx https://msdn.microsoft.com/zh-CN/library/6a71f45d.aspx

Is this simply the price to pay to make language look "succinct" or historical ML roots? 这仅仅是为了使语言看起来“简洁”或历史ML根源而付出的代价?

I'm not sure that looking at the two lists from MSDN necessarily gives a fair comparison. 我不确定查看MSDN上的两个列表是否一定能得出公平的比较。 Note that the F# table lists anything where a symbolic character is used as part of an expression - this includes things like string literals " , comments /// , pre-processor directives # , quotations, syntax for generics and many others. On the other hand, the C# reference only lists operators (though there are a few keywords too). 请注意,F#表列出了将符号字符用作表达式一部分的任何内容-包括诸如字符串文字" ,注释/// ,预处理器指令# ,引号,泛型语法以及许多其他内容。一方面,C#参考仅列出了运算符(尽管也有一些关键字)。

It is true that F# has a few more operators than C#, but I don't think the difference is as huge as you might think. 的确,F#比C#具有更多的运算符,但我认为差异不像您想象的那么大。 The most notable are: 最值得注意的是:

  • Operators for working with functions like >> and |> (and variations on those) 使用>>|>类的函数的运算符(以及这些函数的变体)
  • Operators for working with lists like :: (prepend element) and @ (concatenation) 用于处理列表的运算符,例如:: :(前置元素)和@ (并置)
  • Operators for dealing with nullable values (many with ? on some side), though I think of these more as workarounds to enable LINQ interop than fundamental operators of F# 用于处理可为空的值的运算符(在某些方面带有许多? ),尽管我认为这些要比支持F#的基本运算符更多地是支持LINQ互操作的解决方法

  • There are a few operators for mutable ref cells := and ! 可变引用单元格有一些运算符:=! - I think these are mainly ML heritage and you don't really need them as often. -我认为这些主要是ML的遗产,您实际上并不需要那么频繁。

So, I think the main thing is that F# just has a few more data types that are at the core of functional programming and it has operators for working with them (especially functions and lists). 因此,我认为最主要的是F#只是功能编程核心中的其他几种数据类型,并且它具有用于处理它们的运算符(尤其是函数和列表)。 On the other hand, a couple of the things from the C# list ( typeof , sizeof , delegate and also += and such are either functions in F# or are not needed at all). 另一方面,C#列表中的几件事( typeofsizeofdelegate+=等都是F#中的函数,或者根本不需要)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM