-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make postprocessing configurable #80
base: master
Are you sure you want to change the base?
Conversation
Copy/paste error from 'defaultPostProcess'.
@@ -43,5 +45,6 @@ data Expr | |||
-- only thing we will be doing with it is turning it /back/ into a string | |||
-- at some stage, so we might as well cut out the middle man and store it | |||
-- directly like this. | |||
| CustomExpr Style !String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This opens up a lot of flexibility. But it feels slightly ugly, since we will never actually parse a CustomExpr
. We could formalise that fact with GADTs and DataKinds, but it's possibly unwarranted complexity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good to me!
Helps with defining Show instance.
should probably be undone, effectively just stashing them
I'm spitballing here, and I'm not sure where it falls on a spectrum anywhere from making this redundant to being completely orthogonal, but anyway, if I ever return to this, I think we should look in to integrating import Data.Data
import Data.Generics.Aliases
import Text.Pretty.Simple
gshowWith :: (Data a, Typeable b) => (b -> String) -> a -> String
gshowWith f x = gshowsWith f x ""
gshowsWith :: (Data a, Typeable b) => (b -> String) -> a -> ShowS
gshowsWith f =
( \t ->
showChar '('
. (showString . showConstr . toConstr $ t)
. (foldr (.) id . gmapQ ((showChar ' ' .) . gshowsWith f) $ t)
. showChar ')'
)
`extQ` (shows :: String -> ShowS)
-- only here do we modify the definition of `gshows`
`extQ` ((++) . f)
data Example = Example Int String Word | Rec () Example deriving (Data, Typeable)
example :: Example
example = Rec () $ Example 42 "Hello" 15
main :: IO ()
main =
pPrintString $
gshowWith
(\(i :: Int) -> "<int: " ++ show i ++ ">")
example ( Rec ( () )
( Example <int: 42> "Hello" ( 15 ) )
) |
Ended up writing a fix for #39, to help with a script I was writing this afternoon.
Not quite sure about the details of the API yet.
Tests expected to fail right now, though fixes should be trivial. And new tests will be added anyway.