# Is this overkill?

6 messages
Open this post in threaded view
|

## Is this overkill?

 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? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090403/4a7bc302/attachment.htm
Open this post in threaded view
|

## Is this overkill?

 On Fri, Apr 03, 2009 at 08:58:41PM -0500, Zachary Turner wrote: > trueIndices = curry \$ map fst . filter snd . zip [0..] . map (uncurry (&&)) > . (uncurry zip) Just some tips: note that   map (uncurry f) . zip  ===  zipWith f   curry \$ f . uncurry g  ===  (f .) . g so   trueIndices = ((map fst . filter snd . zip [0..]) .) . zipWith (&&) There must be some combinators to avoid the '((...) .) .' thing, though. I just don't remember :). HTH, -- Felipe.
Open this post in threaded view
|

## Re: Is this overkill?

 In reply to this post by Zachary Turner-2 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
Open this post in threaded view
|

## Re: Is this overkill?

 On Fri, Apr 3, 2009 at 9:30 PM, Heinrich Apfelmus <[hidden email] > wrote: > 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 (&&)) > That was a pretty interesting blog post, and easily understandable which is always nice.  Thanks for the link.  I also had never even used the zipWith function, so thanks for pointing out that equivalence. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090403/691113d2/attachment.htm