
Zachary Turner wrote:
I thought I would try to see if it were possible to write, in point-free form using no lambda functions and no intermediate functions, a function that takes 2 lists of Booleans, computes the pairwise logical AND of the two lists, and returns a list containing the 0 based indices of the elements where the logical and of the two was true. I know that at some point it becomes overkill and for the sake of readability one should know when to draw the line. So I want to see if someone with more experience than me can comment on whether or not this is over the line :P
trueIndices = curry $ map fst . filter snd . zip [0..] . map (uncurry (&&)) .. (uncurry zip)
So do all the uncurries and curries make it too hard to understand or is it pretty easy to read this? For me it takes me a while to figure out by looking at it because it's hard to trace all the currying and uncurrying. And is there a more elegant solution?
Looks very readable to me, though I'd write it as trueIndices = (map fst . filter snd . zip [0..] .) . zipWith (&&) or even simply as trueIndices xs ys = map fst . filter snd . zip [0..] $ zipWith (&&) xs ys because composing functions with more than one argument tends to be a bit messy. With Conal's semantic editor combinators http://conal.net/blog/posts/semantic-editor-combinators/ it would be written as trueIndices = (result . result) (map fst . filter snd . zip [0..]) (zipWith (&&)) Regards, apfelmus -- http://apfelmus.nfshost.com