Consider this expression (taken from Real World Haskell ch. 8, which I try to simplify)
isElfFile :: FilePath -> IO Bool
isElfFile path = return . hasElfMagic =<< L.readFile path
How do I make a point-free version of this function? I tried using its the other bind operation >>=, lifting hasElfMagic, but none seems to be working.
It's simpler without binding here:
isElfFile path = return . hasElfMagic =<< L.readFile path
isElfFile path = fmap hasElfMagic (L.readFile path)
isElfFile = fmap hasElfMagic . L.readFile
But of course also doable with =<<:
isElfFile path = return . hasElfMagic =<< L.readFile path
isElfFile path = (=<<) (return . hasElfMagic) (L.readFile path)
isElfFile = (=<<) (return . hasElfMagic) . L.readFile
isElfFile = (return . hasElfMagic =<<) . L.readFile
In general, it helps to convert infix functions into prefix form before trying make things point-free.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With