Mike Gunter writes:
The ____By functions in the 1.3 PreludeList (elemBy, deleteBy, etc.)
all take ``equality'' predicates with type a -> a -> Bool. Most of
these functions (with no change in definition that I see in a quick
check) could take predicates with type a -> b > Bool (with a
corresponding change in the type of the other arguments). For
example, I find myself wanting to use
elemBy :: (a -> b -> Bool) -> a -> [b] -> Bool
elemBy = any (eq x)
while the draft prelude has
elemBy :: (a -> a -> Bool) -> a -> [a] -> Bool
elemBy = any (eq x)
...
Alastair Reid ([EMAIL PROTECTED]) notes that the names
"elem", "Eq", "eq" are not good here because this (a -> b -> Bool)
a
might be not an equivalence,
and he gives some other notices.
--------------------------------------------------------------------
Why, the subject is quite simple:
relatedToAny :: (a -> b -> Bool) -> a -> [b] -> Bool
relatedToAny r x ys = any (r x) ys
This means
"x is related to some y from ys by the given Binary Relation r".
And it is better to replace elem, elemBy::(a -> a -> Bool) ...
with this relatedToAny - for it is more general and still simple.
Am I missing something ?
--------------------------------------------------------------------
But
why at all should such "empty" functions present in the Prelude ?
Is not it more natural for the programmer to write, say,
if any (r 'a') ys ... (1)
instead of if elemBy r 'a' ys ... (2)
or even if relatedToAny r 'a' ys ... (3)
- ?
(1) is evidently more plain.
- ?
Regards,
Sergey Mechveliani [EMAIL PROTECTED]