[Haskell-cafe] wanted: haskell one-liners (in the perl sense of one-liners)

David Roundy droundy at darcs.net
Fri Mar 2 12:25:04 EST 2007


On Fri, Mar 02, 2007 at 03:17:10PM +0100, Bas van Dijk wrote:
> On Friday 02 March 2007 14:48, Thomas Hartman wrote:
> > ...
> > But I couldn't figure out how to use them directly from the shell, and
> > of course that's what most readers will probably wnat.
> > ...
> 
> From Dons wiki article http://haskell.org/haskellwiki/Blog_articles I noticed 
> this blog with a nice tip on how to run Haskell expressions from the shell:
> 
> http://www.joachim-breitner.de/blog/archives/156-Haskell-on-the-Command-Line.html

I liked this trick (which involves writing bash functions that call ghc
-e), but am a little disappointed that I can't see how to import modules
using ghc -e, which rather severely limits what I can do with one liners.
Ideally you'd at least like to be able to do something like:

in my .bashrc:

if which ghc >/dev/null
    then
            function hrun { ghc -e "interact($*)";  }
            function hmap { hrun "map($*)";  }
            function hmapl { hrun  "unlines.map($*).lines" ; }
            function hmapw { hmapl "(unwords.map($*).words)" ; }
    fi

then I'd like to run

echo hello world | hmap toUpper

but there's no way that I can see to import Data.Char either on the command
line, or as a flag passed by hrun to ghc.  Ideally one would want the bash
function to always deal with importing Data.Char, one of the regexp
libraries, etc.

Any suggestions?
-- 
David Roundy
Department of Physics
Oregon State University


More information about the Haskell-Cafe mailing list