For all haskell-loving folks out they, consider these lines as an addon to your .bashrc:
if which ghc >/dev/null
then
function hmap { ghc -e "interact ($*)"; }
function hmapl { hmap "unlines.($*).lines" ; }
function hmapw { hmapl "map (unwords.($*).words)" ; }
fi
This is somewhat an replacement to "perl -e", for cases where haskell does the job nicer. So, you like triangular text files? Then try
cat /etc/passwd | hmapl zipWith take [1..]
In most cases, you want to run hmapl with map or filter as the first argument, e.g.
cat /etc/passwd | hmapl map reverse
w|hmapl 'filter (List.isPrefixOf "j")' # essentially grep ^j
man ghc|hmapw 'filter (all Char.isAlpha)'
Trackbacks