我想做这个功能
addAndDrop x y = x + 1
Run Code Online (Sandbox Code Playgroud)
点免费.我明白这一点:
addAndDrop x y = (+1) x
Run Code Online (Sandbox Code Playgroud)
但是从这里我可以采取两种不同的途径.
--First path:
addAndDrop x y = const ((+1) x) y
addAndDrop x = const ((+1) x)
addAndDrop x = (const . (+1)) x
addAndDrop = const . (+1) --I'm done!
--Second path:
addAndDrop x y = (+1) (const x y)
addAndDrop x y = ((+1) . (const x)) y
addAndDrop x = (+1) . (const x) --Here I'm stuck!
Run Code Online (Sandbox Code Playgroud)
在第一条道路上一切顺利.但在第二条道路上,我陷入困境.
有没有办法继续并完成第二条路径,或者我真的卡住了,因为我认为我是?
如果我真的被卡住了,是否有任何基本的幻想,数学/功能/无论什么原因导致我陷入一条路而不是另一条路?
Dan*_*tin 11
--Second path:
addAndDrop x y = (+1) (const x y)
addAndDrop x y = ((+1) . (const x)) y
addAndDrop x = (+1) . (const x) --Here I'm stuck!
addAndDrop x = ((+1) .) (const x)
addAndDrop x = (((+1) .) . const) x
addAndDrop = ((+1) .) . const
Run Code Online (Sandbox Code Playgroud)
一般情况下,模式是\x -> f . (g x)
变(f .) . g