Swirly Mein Kopf

Monday, July 24. 2006

Haskell on the Command Line

Haskell

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


No Trackbacks

Comments

Display comments as (Linear | Threaded)

*discussed at

http://www.nabble.com/wanted%3A-haskell-one-liners-%28in-the-perl-sense-of-one-liners%29-tf3333697.html
#1 Anonymous on 2007-03-02 20:16 (Reply)
*Manual trackback:

http://caos.di.uminho.pt/~ulisses/blog/2008/04/20/top-10-programs-haskell-version/
#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.
CAPTCHA

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