Haskell:一个组合案例

时间:2017-12-20 14:32:04

标签: haskell function-composition

这是通过foldl连接的无用案例,纯粹是教育性的(对我而言):

foldl (\xs x -> xs ++ [x]) [1,2] [11,12,13]
[1,2,11,12,13]

有没有办法将它打包得更紧,使用构图而不是lambda?

1 个答案:

答案 0 :(得分:1)

这是从HTNWWill Ness的评论中提取的更易读的摘要:

-- Reduction to poinfree
a = \xs x -> xs ++ [x]
b = \xs x -> xs ++ return x
c = \xs x -> ((xs ++) . return) x
d = \xs x -> ((. return) (xs ++)) x
e = \xs x -> ((. return) . (++)) xs x