-
Notifications
You must be signed in to change notification settings - Fork 4
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
makeLiftShowsPrec doesn't work for recursive types #5
Comments
Recursive datatypes are unfortunately the Achilles heel of these In light of this fact, the Haddock's claim that it doesn't require a |
I'd consider this bug fixed, but I think it would then warrant a feature request allowing using I've not looked at the internals of this function, but would it be possible to make the resulting value a fixed point. Something like this: makeLiftShowsPrec ''Foo =
let s = <some expression using 's' in place of 'liftShowsPrec' for 'Foo'>
in s A map from (type) |
Well, the primary use case for newtype Fix f a = Fix (f (Fix f a))
instance Show (f (Fix f a)) => Show (Fix f a) where
showsPrec = $(makeShowsPrec ''Fix) The scenario you describe is interesting, but not quite a generalization of what the newtype Fix f a = Fix (f (Fix f a))
showFix = $(makeLiftShowsPrecTwo ''Fix) What code should be spliced here? A naïve translation would be something like this: let lspf = \sp sl p value -> case value of
Fix f -> showParen (p > 10) $
showString "Fix "
. liftShowsPrec (lspf sp sl) (liftShowList sp sl)
11 f
in lspf But that still doesn't work, because it requires an invocation of let lspf = \sp sl p value -> case value of
Fix f -> showParen (p > 10) $
showString "Fix "
. liftShowsPrec (lspf sp sl) (lsl sp sl)
11 f
lsl = \sp sl -> showListWith (lspf sp sl 0)
in lspf This works, but the semantics have changed slightly, since instance Show1 List where
liftShowsPrec = $(makeLiftShowsPrec ''List)
liftShowList = {- a custom list show function -} So if this feature were to be implemented, I'd want it not to be the default, but rather opt-in (perhaps via an |
That's a good example; sounds very reasonable. |
This requires an instance of
Show1
forMap
, There seems to be no way to get this behavior without derivingShow1
forMap
.The text was updated successfully, but these errors were encountered: