As noted multiple times elsewhere (eg. 1,2,...) scripting in haskell can be quite powerful.
A quick way can also be the ghc expression evaluation mode. this is what I actually find myself using more and more (I really like this feature in ruby).
A little example task:
"Find out all the folders that contained git diffs between the HEAD and a specific revision"
git diff --stat 9e2b68 | ghc -e \
"getContents >>= return.(Data.List.nub).map(fst.break('/'==).head.words).lines"
This looks a little clunky, probably because I don't really know the details of using ghc -e
.
Given that all the interesting part is just the nub.map(fst.break('/'==).head.words).lines
the actual expression seems a little wordy.
- How do I tell ghc about modules I need to use so I don't need to qualify them using the full name?
- Can I make ghc pick up some kind of a configuration file that contains modules I frequently use?
I'd really appreciate seeing some examples from other usecases that will help my improve the way I use haskell for those kinds of little scripts!
Sidenote: Commandline-foo wizards will probably laugh at this but I feel much more comfortable using haskell then bash scripting so this is what I want to use.
interact
to be a little less clunky:ghc -e "interact $ <String -> String func>"
. This frequently ends up asghc -e "interact $ unlines . map (<String -> String func>) . lines"
.