Swirly Mein Kopf

Monday, July 24. 2006

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


No Trackbacks


Display comments as (Linear | Threaded)

*discussed at

#1 Anonymous on 2007-03-02 20:16 (Reply)
*Manual trackback:

#2 Joachim Breitner (Homepage) on 2008-04-21 15:17 (Reply)

Add Comment

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.

What is the first name of the owner of this blog? / Wie heißt der Betreiber dieses Blogs mit Vornamen?
Nach oben