Reputation: 1744
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.
Upvotes: 3
Views: 431
Reputation: 30103
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.
Upvotes: 8