For example, one wants to use Fold
function to implement an unique
(or DeleteDuplicates
) function, which accepts 1-dimensional array and returns the same, but shorter. I am against it, but I can't find proof in any Wikipedia, why it is a bad practice.
Asked
Active
Viewed 39 times
-1

Nakilon
- 34,866
- 14
- 107
- 142
-
1Why do you think it would be a bad practice? – Nov 26 '13 at 13:28
-
A lot of things can be implemented in terms of fold. It's an incredibly general function. By all means, use it where it fits naturally. – KChaloux Nov 26 '13 at 14:03
1 Answers
0
If you look at the types of various Haskell folds:
foldr :: (a -> b -> b) -> b -> [a] -> b
foldl :: (b -> a -> b) -> b -> [a] -> b
you can clearly see that such a thing is perfectly legal -- just substitute in [a]
for b
.
And indeed, there are several examples in core libraries of folds used with such types. There are even examples where the "number of dimensions" is increased using a fold.
Why are you against it?

Matt Fenwick
- 48,199
- 22
- 128
- 192