
Well, sort of. Ok, we can parse that. Let's assume a variable x holds the output of :show modules as a String. We call lines on it, then map words on it, do a !! 2 on it, and we get ["Util.hs,", "Recorder.hs,", "Game.hs,", "Monadius.hs,", "Demo.hs,"]. Chuck in a map (filter (\= ',')), and we get a good list. We can turn the list into a string suitable for hlint with a quick unwords.
So our long sought after command becomes ':def hoogle (\_ -> return $ ":! " ++ (unwords $ map (filter (\= ',')) $ (map words $ lines x) !! 2))'. But wait, how do we get 'x'? How do we call :show modules inside a Haskell expression?
The first url includes a link to a .ghci mini-tutorial (section 4) that, among other things, implements :redir <var> <cmd> -- execute <cmd>, redirecting stdout to <var>
Perhaps my cold has fogged my head too much, but I'm not sure how :redir would help. I could do :redir var "hlint .", but that's as unsatisfactory as :! "hlint ."
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). Claus
participants (1)
-
Claus Reinke