水晶郎咖喱

时间:2018-03-18 19:23:53

标签: crystal-lang

我尝试在Crystal中创建curried add proc。如何让这个例子起作用?

RDD[(Long, VertexAttributes)]

https://play.crystal-lang.org/#/r/3r0g

我收到错误

没有超载匹配' Proc(Int32,Int32)#call'类型为Int32,Int32 超载是:   - Proc(T,R)#call(* args:* T)

1 个答案:

答案 0 :(得分:5)

the proc documentation开始,Proc(Int32, Int32)是一个过程,需要一个Int32并返回一个Int32。你的意思是使用Proc(Int32, Int32, Int32)。此外,您需要使用semi_curry.call(add).call(5).call(6)

semi_curry = ->(f: Proc(Int32, Int32, Int32)) { ->(a: Int32) { ->(b: Int32) { f.call(a, b) } } }

add = ->(a: Int32, b: Int32) {a + b}

p semi_curry.call(add).call(5).call(6)

https://play.crystal-lang.org/#/r/3r0m

如果您希望在应用程序中考虑过程,而不是学习练习,则应使用Proc#partial代替。

相关问题