SwirlyMyself

2006-07-24T21:00:51+00:00

Haskell on the Command Line

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

Comments

discussed at

http://www.nabble.com/wanted%3A-haskell-one-liners-%28in-the-perl-sense-of-one-liners%29-tf3333697.html
#1 Anonymous am 2007-03-02T19:16:13+00:00
Manual trackback:

http://caos.di.uminho.pt/~ulisses/blog/2008/04/20/top-10-programs-haskell-version/
#2 Joachim Breitner (Homepage) am 2008-04-21T13:17:36+00:00

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