首页 \ 问答 \ Currying:实际意义(Currying: practical implications)

Currying:实际意义(Currying: practical implications)

我对这个问题的理解来自Heilperin等人。 “混凝土抽象” 。 我得到的结论是对函数的求值的转换,该函数将几个参数用于评估函数序列,每个函数都有一个参数。 我清楚了两种方法之间的语义差异(我可以这样称呼它们吗?)但我确信我没有掌握这两种方法背后的实际意义。

请考虑在Ocaml中:

# let foo x y = x * y;;
foo : int -> int -> int = <fun>

# let foo2 (x, y) = x * y;;
foo2 : int * int -> int = <fun>

两个函数的结果相同。 但是,实际上,这两个功能有什么不同呢? 可读性? 计算效率? 我缺乏经验不能给这个问题足够的阅读。


My comprehension of the problem comes from Heilperin's et al. "Concrete Abstraction". I got that currying is the translation of the evaluation of a function that takes several arguments into evaluating a sequence of functions, each with a single argument. I have clear the semantic differences between the two approaches (can I call them this way?) but I am sure I did not grasp the practical implications behind the two approaches.

Please consider, in Ocaml:

# let foo x y = x * y;;
foo : int -> int -> int = <fun>

and

# let foo2 (x, y) = x * y;;
foo2 : int * int -> int = <fun>

The results will be the same for the two functions. But, practically, what does make the two functions different? Readability? Computational efficiency? My lack of experience fails to give to this problem an adequate reading.


原文:https://stackoverflow.com/questions/39835395
更新时间:2021-06-09 21:06

最满意答案

   lapply(v, function(i){
      print(i)
      s = some.complex.function.that.updates.s(s)
      return(s)
   })

结果将是为v每个值创建的对象列表。 即使它应该已经传递了v的值,因为它是该函数执行的最后一个操作。


   lapply(v, function(i){
      print(i)
      s = some.complex.function.that.updates.s(s)
      return(s)
   })

the result will be a list of object s created for each value of v. Even if it should have passed the value of v anyway cause it was the last operation performed by the function.

相关问答

更多
  • 定义do_usemethod的C源文件中的以下评论至少暗示了发生了什么。 特别参见第二个枚举项目的第二句。 基本上,它看起来像(由于第二点中的规则应用不严格),x的值并没有被复制,因为C代码检查它是否在形式中,看到它是,并且如果排除插入到方法评估环境中的变量列表。 /* usemethod - calling functions need to evaluate the object * (== 2nd argument). They also need to ensure that the * argum ...
  • 我不认为这是编译器中的错误,因为我认为这是@for循环的预期行为,但你是正确的,因为它没有记录 。 我会提交一份请求 , 要求澄清/添加到官方文档中。 I don't think this is a bug in the compiler as I believe this to be the intended behavior of the @for loop, but you're correct in that that it's not documented. I would submit a re ...
  • 在您的代码中,您已经定义了i和j多个实例(每个实例占用自己的内存空间)。 至少这导致难以理解和不可维护的代码: int i = 0, int j = 0; //i & j defined here for(int i = 0; i < 10; i++){//and new i here static int j = 0;//new j defined here with new block scope. 关于范围:此代码片段没有意义,只是为了说明每次出现的i都是一个单独的变量,因 ...
  • 我对OP的追求与@ josilber相同的猜测。 这是一个非基本的R方式: library(data.table) setDT(data)[, c("x","y") := {ii = which.max(area) ; list(x[ii], y[ii])}, by = POSTAL] (就给出的例子而言,这只在第39行进行了一次改变。) My guess for what the OP's seeking is the same as @josilber's. Here's a non-base R w ...
  • 基本上,由于您使用的是“< - ”赋值,因此该函数正在创建“全局”变量的副本,以便在函数范围内使用。 这可以通过在第二个函数g()中添加一个函数g()来实现,该函数在f()打印出来之前改变'global'的值,但这次使用“<< - ”赋值。 f()中的第一行为f(x)创建了'global'的本地范围副本,然后使用g(x)更新'global'的全局副本。 global <<- list() f <- function(x) { global[[x]] <- "blah" g(x) global ...
  • environment(getDetails) = parent.env(environment(getDetails))是一种删除全局范围的方法。 这对我有用。 唯一的问题是,必须为我编写的每个函数执行此操作。 environment(getDetails) = parent.env(environment(getDetails)) is a way to remove the global scope. This works for me. Only problem is, this has to be ...
  • 一种解决方案是使用eval()和parse() : p.val <- eval(parse(text=paste0("summary(",mod.name,")[",paste0(attr.name),"]"))) 所以功能是: mod.pvals <- NULL p.func <- function(attr.name) { for(i in c('dat1','dat2')) { mod.name <- paste0('fit.',i) p.val <- eval(parse(te ...
  • lapply(v, function(i){ print(i) s = some.complex.function.that.updates.s(s) return(s) }) 结果将是为v每个值创建的对象列表。 即使它应该已经传递了v的值,因为它是该函数执行的最后一个操作。 lapply(v, function(i){ print(i) s = some.complex.function.that.updates.s(s) ...
  • 你可以通过Rcpp将R环境传递给C ++就好了; 并且示例存在于文档,此处和其他位置。 然而,随便在那里随机扔一个C ++ extern会访问一个环境。 You can pass R environments down to C++ just fine via Rcpp; and examples exists in the docs, here, and in other places. Just randomly tossing a C++ extern in there, however, does ...
  • 要测试NA ,您需要使用is.na函数。 看到: > 1 != NA # bad [1] NA > !is.na(1) # good [1] TRUE 所以最后,只需要替换: olddata[,paste("q08pa",spell,sep="")]!=NA 同 !is.na(olddata[,paste("q08pa",spell,sep="")]) 你应该没问题。 To test for NA, you need to use the is.na function. See that: ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)