[Haskell-cafe] Re: [Haskell] ANN: HLint 1.0

Gwern Branwen gwern0 at gmail.com
Sat Dec 27 20:53:20 EST 2008

Hash: SHA512

On Fri, Dec 26, 2008 at 5:22 PM, Claus Reinke  wrote:
>>> You were asking about getting the output of ':show modules' into a
>>> variable 'x', so that you can process it further. ':redir x :show
>>> modules'
>>> should do just that. There is another example command for implementing
>>> ':edit' this way (by now a native ghci command).
>> I think I'm seeing your meaning. So that brings me up to this:
>> let hlint _ = return $ unlines [":redir hlintvar1 :show modules", "let
>> hlintvar2 = map (fst . break (==',') . drop 2 . snd . break (== '('))
>> $ lines hlintvar1", ":! hlint (concat $ intersperse \" \" hlintvar2"]
>> :def hlint hlint
>> This doesn't work. The issue is that :! is weird; for it to work, one
>> need to pass each argument as a separate string, and it won't evaluate
>> a variable.
Version: GnuPG v1.4.9 (GNU/Linux)


> It isn't just ':!', quoting/variable interpretation is generally rather
> uncomfortable in GHCi scripting (so much so that I originally submitted
> output redirection as a patch before figuring out that it could be done
> without patching GHCi - that surprise find was the motivation for posting
> my findings as an email).

No kidding. I find ghci scripting pretty awkward. Maybe things would
be better if all the :commands had exposed and easily used Haskell
function equivalents so you could stay on the Haskell level and only
deal with the :commands at the last second.

> Have you tried reading the mini tutorial that I
> keep mentioning and which the "using GHCi" page is pointing to? Here's the
> direct link:
> http://www.haskell.org/pipermail/haskell-cafe/2007-September/032260.html
> The discussion is rather brief, but that tutorial has several examples
> that need to work around issues like this, ranging from simple but
> tedious construct-the-command-string to extra levels of ':cmd' in
> order to get extra levels of interpretation (when you need to construct
> a command string from a variable that will be bound via a constructed
> command string (see the definitions of ':find', ':le' or ':b(rowse)' - the
> latter is an example of using the info from ':show modules').
> Claus

Yes, I have read all that, but I find it difficult to understand. In
some places, there are more levels of quoting and indirection than I
can keep track of (I swear in one place the code must've been 4 levels
deep). But on re-reading, I think :cmd solves my problem. So my
solution looks like this:

let hlint _ = return $ unlines [":redir hlintvar1 :show modules", "let
hlintvar2 = map (fst . break (==',') . drop 2 . snd . br
eak (== '(')) $ lines hlintvar1", ":cmd return (\":! hlint \" ++
(concat $ intersperse \" \" hlintvar2))"]
:def hlint hlint

(:redir obviously coming from your .ghci code.)

This doesn't integrate with :load or anything, but it does let you
just blindly go ':hlint' and get the suggestions.


More information about the Haskell-Cafe mailing list