Joachim Breitner

Haskell on the Command Line

Published 2006-07-24 in sections English, Haskell.

For all haskell-loving folks out they, consider these lines as an addon to your .bashrc:

    if which ghc >/dev/null


function hmap { ghc -e "interact ($*)"; }

function hmapl { hmap "unlines.($*).lines" ; }

function hmapw { hmapl "map (unwords.($*).words)" ; }


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)'


discussed at
#1 Anonymous am 2007-03-02

Have something to say? You can post a comment by sending an e-Mail to me at <>, and I will include it here.