[GHC] #10447: DeriveFoldable rejects instances with constraints in last argument of data type
GHC
ghc-devs at haskell.org
Thu May 28 01:38:48 UTC 2015
#10447: DeriveFoldable rejects instances with constraints in last argument of data
type
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: GHC rejects | Unknown/Multiple
valid program | Test Case:
Blocked By: | Blocking:
Related Tickets: #8678 | Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by RyanGlScott):
> You expect that the {{{Foldable}}} instance for {{{data T2 a = (a ~ Int)
=> MkT2 Int}}} give you the {{{Int}}} because there happens to be an
{{{Int}}} equality constraint?
That is what I am expecting, yes, especially since {{{T1}}}, {{{T2}}}, and
{{{T3}}} are equivalent representations of the same thing.
> That seems pretty unintuitive to me. What about e.g. {{{data E = E
Int}}}, and {{{data A a = A E}}} vs. {{{data A a = (a ~ Int) => A E}}},
and then inlining E?
I'm not sure how inlining would cause a derived {{{Foldable}}} instance
for {{{data A a = (a ~ Int) => A E}}} to fail. Does inlining occur before
{{{DeriveFoldable}}} generates its code? If so, I don't see how GHC could
confuse {{{E}}} for {{{Int}}}.
> derived {{{Foldable}}} instances in the presence of equality constraints
need some more justification.
I find myself wanting to derive {{{Foldable}}} instances for deeply
embedded DSLs that are represented as GADTs. Here's a simple example from
[https://github.com/ku-fpg/hermit-
ghci/blob/8a7556bc53a2e79fb46a807875e913d753b5da37/src/HERMIT/API.hs#L57-58
hermit-ghci]:
{{{#!hs
data ShellEffect :: * -> * where
ShellEffect :: Value -> ShellEffect ()
}}}
(which could equivalently be represented as {{{ShellEffect :: a ~ () =>
Value -> ShellEffect a}}})
This isn't a {{{Functor}}} or {{{Traversable}}}, but it readly admits a
{{{Foldable}}} instance which {{{DeriveFoldable}}} would be able to infer:
{{{#!hs
instance Foldable ShellEffect where
foldr f z (ShellEffect a) = z
foldMap f (ShellEffect a) = mempty
}}}
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10447#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list