yav / pretty-show

Tools for working with derived Show instances in Haskell.
MIT License
57 stars 15 forks source link

Didn't format this one #17

Closed drautzburg closed 9 years ago

drautzburg commented 9 years ago

Usually ppShow did a good job for me, but on this show it does not format:


*AllData> show exSys
"Sys {sysId = 3, sysRand = 2 1, sysProcesses = fromList [(0,Prc {prcId = 0, prcSources = [(\"in\",1,1)], prcSinks = [(\"out\",1,2)], prcParams = PrpBelt 10.0}),(1,Prc {prcId = 1, prcSources = [(\"in\",1,2)], prcSinks = [(\"out\",1,3)], prcParams = PrpBelt 11.0}),(2,Prc {prcId = 2, prcSources = [(\"in\",1,3)], prcSinks = [(\"out\",1,4)], prcParams = PrpBelt 12.0})], sysItems = fromList []}"

*AllData> putStrLn $ ppShow exSys
Sys {sysId = 3, sysRand = 2 1, sysProcesses = fromList [(0,Prc {prcId = 0, prcSources = [("in",1,1)], prcSinks = [("out",1,2)], prcParams = PrpBelt 10.0}),(1,Prc {prcId = 1, prcSources = [("in",1,2)], prcSinks = [("out",1,3)], prcParams = PrpBelt 11.0}),(2,Prc {prcId = 2, prcSources = [("in",1,3)], prcSinks = [("out",1,4)], prcParams = PrpBelt 12.0})], sysItems = fromList []}

smaller parts are rendered correctly


*AllData> putStrLn $ ppShow (sysProcesses exSys)
fromList
  [ ( 0
    , Prc
        { prcId = 0
        , prcSources = [ ( "in" , 1 , 1 ) ]
        , prcSinks = [ ( "out" , 1 , 2 ) ]
        , prcParams = PrpBelt 10.0
        }
    )
  , ( 1
    , Prc
        { prcId = 1
        , prcSources = [ ( "in" , 1 , 2 ) ]
        , prcSinks = [ ( "out" , 1 , 3 ) ]
        , prcParams = PrpBelt 11.0
        }
    )
  , ( 2
    , Prc
        { prcId = 2
        , prcSources = [ ( "in" , 1 , 3 ) ]
        , prcSinks = [ ( "out" , 1 , 4 ) ]
        , prcParams = PrpBelt 12.0
        }
    )
  ]
drautzburg commented 9 years ago

It seems to have a problem with the random number generator


*AllData> show (mkStdGen 1)
"2 1"
*AllData> reify (mkStdGen 1)
Nothing
yav commented 9 years ago

Indeed, "2 1" does not look like a standard Haskell value, so pretty-show does not understand it.

Basically, pretty-show will work as long as your datatypes have Show instances that are automatically derived or follow the same structure as the automatically derived instances, and otherwise it gives up, as it has no way to know how to interpret the input.

I'll have a look to see if I can relax the parser a bit so that it will also accept this sort of non-standard format, but no promises :-)

yav commented 9 years ago

OK, generalizing the parser to support this pattern turned out to be fairly easy. I just uploaded a version to hackage (1.6.9) that should be able to handle this instance.

drautzburg commented 9 years ago

Works like a charm. Thanks