简体   繁体   English

功能编程:Curry&Fold - 什么是词源?

[英]Functional programming: Curry & Fold - what are the etymologies?

  1. Curry & Fold - what are the etymologies in the programmatic sense? CurryFold - 程序意义上的词源是什么? I do not see how any of the English meanings of these homonyms is related to the functionality of these terms. 我没有看到这些同音异义词的任何英语含义与这些术语的功能有何关系。

  2. If you had to rename them to something more obvious - how would you do it? 如果你不得不将它们重命名为更明显的东西 - 你会怎么做?

Curry is the last name of Haskell Curry, a prominent 20th century logician after whom Haskell got its name . 库里是Haskell Curry的最后一个名字,Haskell Curry是20世纪着名的逻辑学家,Haskell得名于此

And "folding" simply because the fold operator figuratively represents folding, like a hand of cards can be folded to look like a single card. 并且“折叠”仅仅因为折叠操作符比喻地表示折叠,就像一手牌可以折叠成看起来像一张卡片。 Think of foldr (+) 0 [1,2,3] == 6 as a hand of cards 1, 2 and 3 folded into a single card 6. foldr (+) 0 [1,2,3] == 6折叠器foldr (+) 0 [1,2,3] == 6作为卡片1,2和3折叠成一张卡片6。

The word "reducing", which also means folding, can be illustrated using a similar analogy. “减少”这个词也意味着折叠,可以用类似的类比来说明。

Of course, Haskell is more magic than even the bluffiest and luckiest game of poker, so folds in functional programming can actually produce a deck of cards that holds more cards than the hand it was folded from, or cards can be folded into cats, etc: foldr (\\i, acc -> [show i,show i,show i] ++ acc) [] [1,2,3] == ["1","1","1","2","2","2","3","3","3"] . 当然,Haskell甚至比最虚弱和最幸运的扑克游戏更具魔力,因此功能性编程中的折叠实际上可以产生一副卡片,其卡片比折叠的卡片更多,或者卡片可以折叠成猫等等。 : foldr (\\i, acc -> [show i,show i,show i] ++ acc) [] [1,2,3] == ["1","1","1","2","2","2","3","3","3"] Therefore what started out as folding eventually evolved into an extremely universal operator that can produce map as well as filter etc, so don't get too carried away with the poker comparison and etymology. 因此,最初的折叠最终演变成一个极其通用的运算符,可以生成mapfilter等,所以不要太过于扑克比较和词源。


As to what to name them to: renaming a dead person might not be the most ethical thing to do. 至于如何命名他们:重命名一个死人可能不是最合乎道德的事情。 The poor guy is so successful BOTH of his names are used for big things, and then you want to deprive him posthumously of his joy and rename him to something else? 这个可怜的家伙是如此成功,他的名字被用于大事,然后你想剥夺他追求他的喜悦并将他改名为别的东西? Unless perhaps that something else is Newton Watt Scoville or Kelvin Celsius Ângström, I'd seriously not attempt a rename. 除非其他东西是Newton Watt Scoville或KelvinCelsiusÂngström,否则我真的不会尝试重命名。

However if you meant renaming the programming concept: it could instead be referred to by the name "ricing" in my hungry opinion. 但是,如果你的意思是重命名编程概念:在饥饿的意见中,它可以用名称“ricing”来引用。 But Mr. Curry might still feel intimidated. 但库里先生可能仍然感到害怕。

Folding could actually be renamed to bluffing, if you're not fulfilled by the multitude of presently available names for it — thanks to som-snytt for the constructive idea. 折叠实际上可以被重命名为虚张声势,如果你没有满足它的众多现有名称 - 感谢som-snytt的建设性想法。

I believe that the "fold" term comes mainly from the use of the word "fold" in phrases like "to fold into..." which is a term most commonly used by chefs, I believe (I watch a lot of cooking shows...). 我相信“折叠”一词主要来自于“折叠成......”这样的词语中使用“折叠”一词,这是厨师最常用的词,我相信(我看了很多烹饪节目) ...)。 We use it in the context of functional programming because we say that, for example, for lists, the head of the list is "folded into" the resulting of folding the tail. 我们在函数式编程的上下文中使用它,因为我们说,例如,对于列表,列表的头部被“折叠”到折叠尾部的结果中。 For example, the function foldr is a "recipe" for how to "cook" a list, and part of that recipe is "fold this into that", if you like. 例如,函数foldr是如何“烹饪”列表的“配方”,如果您愿意,该配方的一部分是“将其折叠成”。

The oldest reference to "folding" that I could find on the internet in the context of functional programming in this report, published in 1985 by the University of Cambridge, which has this to say: 在剑桥大学1985年出版的报告函数编程中,我可以在互联网上找到最早的“折叠”参考文献,其中有这样的说法:

The function gather applies a function of two arguments “between” each element of a list and a terminal value. 函数gather应用列表的每个元素和终端值之间“两个”参数的函数。 [...] This function is also known as reduce or fold in other languages. [...]此功能在其他语言中也称为缩小折叠

So clearly the term "fold" was at least somewhat common even 30 years ago! 很明显,即使30年前,“折叠”一词至少也有些普遍!

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

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