
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?

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.

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

On Fri, Apr 3, 2009 at 9:30 PM, Heinrich Apfelmus 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.

On Sat, Apr 4, 2009 at 5:20 AM, Zachary Turner
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.
I'm not sure you really want to write this pointfree... Generally I tend to avoid it when there's two arguments of identical standing. Also the (map fst . filter snd...) is a Data.List function (findIndices) : trueIndices xs ys = findindices id $ zipWith (&&) xs ys I love the pointfree style and it might be a good exercise to try and transcribe any function to pointfree, but sometimes pointful is just clearer. -- Jedaï

Chaddaï Fouché wrote:
On Sat, Apr 4, 2009 at 5:20 AM, Zachary Turner
wrote: 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.
I'm not sure you really want to write this pointfree... Generally I tend to avoid it when there's two arguments of identical standing. Also the (map fst . filter snd...) is a Data.List function (findIndices) :
trueIndices xs ys = findindices id $ zipWith (&&) xs ys
I love the pointfree style and it might be a good exercise to try and transcribe any function to pointfree, but sometimes pointful is just clearer.
Or to put it differently, sometimes "pointfree is pointless" ;-) /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe Haskell is an even 'redder' pill than Lisp or Scheme. -- PaulPotts
participants (5)
-
Chaddaï Fouché
-
Felipe Lessa
-
Heinrich Apfelmus
-
Magnus Therning
-
Zachary Turner