ipprint-0.2: IPPrint.hs
module IPPrint(pprint) where
import Language.Haskell.Parser
import Language.Haskell.Pretty
import Text.Read
pprint :: Show a => a -> IO ()
pprint v = putStrLn $
case parseModule ("value = "++s) of
ParseOk m -> tidy $ prettyPrint m
ParseFailed _ _ -> s
where s = show v
tidy x = case readPrec_to_S skipBoring 0 x of
[((), tail)] -> " " ++ tail
_ -> s
skipBoring :: ReadPrec ()
skipBoring =
do { Ident "value" <- lexP; Punc "=" <- lexP; return () } <++
do { lexP; skipBoring }