Alexey Orlov
Alexey Orlov

Reputation: 2814

Haskell: a case of composition

This is a useless case of concatenation via foldl, purely educational (for me):

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

Is there a way to pack it even tighter, using composition instead of the lambda?

Upvotes: 0

Views: 104

Answers (1)

Alexey Orlov
Alexey Orlov

Reputation: 2814

This is just a better readable summary extracted from the comments by HTNW and Will 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

Upvotes: 1

Related Questions