Sign up ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Here's how I implemented concat - flattens a list of lists into just a list of elements.

concat' :: [[a]] -> [a]
concat' ys = foldl (\acc x -> acc ++ x) [] ys

Is it a problem that I'm using the ++ function?

What's a better way to write this?

share|improve this question

1 Answer 1

You could eta-contract the definition in two places: \acc x -> acc ++ x is the eta-expanded version of (++) and concat' ys = (...) ys is the eta-expanded version of concat' = (...). So that would take you to:

concat' :: [[a]] -> [a]
concat' = foldl (++) []

Now, in that case it turns out that it's better to use foldr rather than foldl and there is a good write-up about concat on the haskell wiki.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.