#5499: Tagging constructors with record/product phantom type
----------------------------------+-----------------------------------------
Reporter: basvandijk | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: libraries (other) | Version: 7.2.1
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
----------------------------------+-----------------------------------------
Comment(by basvandijk):
I'm having a bit of trouble using `IsRecord` for changing the dynamic
choice using `conIsRecord` into a static choice. This is the
[https://github.com/basvandijk/aeson/blob/5bdf30ed4b32f2cc169f6e4e58d1688bcb02c197/Data/Aeson/Types/Internal.hs#L925
current code] that uses a dynamic choice:
{{{
instance (Constructor c, GRecordToObject a, GToJSON a) => GToJSON (C1 c a)
where
gToJSON m1@(M1 x)
| conIsRecord m1 = Object $ gRecordToObject x
| otherwise = gToJSON x
}}}
Naively rewriting this to a static choice using `IsRecord`:
{{{
instance (IsRecord a True, GRecordToObject a) => GToJSON (C1 c a) where
gToJSON = Object . gRecordToObject . unM1
instance (IsRecord a False, GToJSON a) => GToJSON (C1 c a) where
gToJSON = gToJSON . unM1
}}}
Doesn't obviously work because we get a `duplicate instance declarations`
error.
So somehow the information, whether a constructor is a record or not, has
to move to the right of the `=>`.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5499#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs