Point-free equivalent

Shanthakumar

I have this function from another SO question,

f :: Ord a => [a] -> [(a, Int)]
f xs = zipWith (\x ys -> (x, length $ filter (< x) ys)) xs (inits xs)

I'm trying to write it in point-free style,

f = flip (zipWith (\x -> (,) x . length . filter (< x))) =<< inits

Is it possible to get rid of that x ?

leftaroundabout

As a general rule: if a variable turns up more than once in an expression, it's probably not a good idea to make it point-free. If you're determined however, the least unreadable way is with the Arrow combinators, because that makes it pretty clear where the data flow is "split". For the xs I'd write

  uncurry (zipWith (...)) . (id &&& inits)

For x, the same method yields

  zipWith ( curry $ uncurry(,) . (fst &&& length . uncurry filter . first(>)) )

This is even longer than the (->)-monad solution that you've used and lambdabot suggests, but it looks far more organised.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Point free version for readMaybe

From Dev

point free procedure composition

From Dev

Point Free problems in Haskell

From Dev

Point free monadic expression

From Dev

Point Free with lists in Haskell

From Dev

point free procedure composition

From Dev

Equivalent Context-Free Grammars

From Dev

Equivalent Context-Free Grammars

From Dev

Is there a delphi ScrollInView equivalent in Free Pascal?

From Dev

Point free function gives different result to non-point free?

From Dev

Can this be expressed in point free style?

From Dev

make function with 'if' point-free

From Dev

Can this be expressed in point free style?

From Dev

Haskell concatMap point free explanation

From Dev

What's the point of free functions?

From Dev

How to make an if statement point free

From Dev

Is Dispose() in C# equivalent to free() in C

From Dev

Delphi equivalent to Free Pascal's FPC define?

From Dev

Delphi equivalent to Free Pascal's FPC define?

From Dev

Why is the point-free style called point free in Haskell when it is full with points? Where does the term "point-free" originates from?

From Dev

point free notation with multiple function parameters

From Dev

Why does this point free definition not work in Haskell?

From Dev

Writing a parameterless function in Ramda in a point free style?

From Dev

Haskell point-free compilation type

From Dev

Got confused with point free style code

From Dev

Transforming a Haskell function to a point free representaion

From Dev

free hand drawing in java using class Point

From Dev

Point-free functions in monadic binding

From Dev

F# point free style division