Search code examples
haskellpointfree

How do I make interact point-free?


shortLinesOnly :: IO ()
shortLinesOnly = interact result
    where
        shortLength     = 11
        onlyShorts      = (<= shortLength) . length
        shortLines      = filter onlyShorts . lines
        result          = unlines . shortLines
        interact result = getContents >>= putStr . result

In the above code how can I write the interact function in point free style.


Solution

  • Step by step:

    interact r = getContents >>= putStr . r
    interact r = (getContents >>=) (putStr . r)
    interact r = (getContents >>=) $ (putStr .) $ r
    interact = (getContents >>=) . (putStr .)