I’ve written a GHC plugin that lets you take things like the following code:
main :: IO ()
main = do
putStrLn "Which argument would you like to print?"
line <- getLine
args <- getArgs
putStrLn $ args !! read line
and instead write this code:
main :: IO ()
main = do
putStrLn "Which argument would you like to print?"
putStrLn $ !getArgs !! read !getLine
This is heavily inspired by Idris’s !-notation, the main difference being that this plugin only allows you to use !
inside of existing do
-blocks, whereas Idris will insert a do
if it doesn’t exist.
It currently works with ghc 9.4. You can find it here:
Please feel free to try it out and let me know what you think!