Type family constraints
Given data GhcPass (c :: Pass) deriving instance Eq (GhcPass c) deriving instance Typeable c => Data (GhcPass c) data Pass = Parsed | Renamed | Typechecked deriving (Data) Is there any way to express that `pass` must be valid for each value of `Pass` in the following instance head? instance (p ~ GhcPass pass, OutputableBndrId p) => Outputable (HsIPBinds p) where This comes from a problem where setting each type family instance separately does not get picked up during instance resolution (and can't be, according to earlier questions by me on this) i.e. type instance XIPBinds (GhcPass 'Parsed) = NoExt type instance XIPBinds (GhcPass 'Renamed) = NoExt type instance XIPBinds (GhcPass 'Typechecked) = TcEvBinds it works fine for type instance XIPBinds (GhcPass _) = NoExt Alan ___ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Re: Type family constraints
> On Apr 23, 2018, at 6:56 AM, Alan & Kim Zimmerman wrote: > > Is there any way to express that `pass` must be valid for each value of > `Pass` in the following instance head? > No, there isn't. And for good reason: whatever you're trying to do likely requires some runtime decision-making, and that's impossible with just type-level information. (Even without that motivation, there's this: any way of doing this would likely break type soundness. See #7259 and #14420.) My recommendation is to have > class ValidPass p > instance ValidPass Parsed > instance ValidPass Renamed > instance ValidPass Typechecked My guess is that you'll need to add a method to ValidPass, anyway. Richard___ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Re: Type family constraints
Thanks Richard Ryan Scott has also put together a solution[1], which is basically what you proposed. But in terms of trying to clean up the code by removing a straightforward constraint type, I think this solution adds more complexity than it removes. So I will leave it as it is. Alan [1] http://lpaste.net/365181 ___ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
RE: Type family constraints
I’m afraid I don’t understand the question. type instance XIPBinds (GhcPass 'Parsed) = NoExt type instance XIPBinds (GhcPass 'Renamed) = NoExt type instance XIPBinds (GhcPass 'Typechecked) = TcEvBinds it works fine for type instance XIPBinds (GhcPass _) = NoExt You mean, the first group does not work, but the latter does?? I’m not even sure what “work” means. I’m perplexed and need more context Simon From: ghc-devs On Behalf Of Alan & Kim Zimmerman Sent: 23 April 2018 11:57 To: ghc-devs Subject: Type family constraints Given data GhcPass (c :: Pass) deriving instance Eq (GhcPass c) deriving instance Typeable c => Data (GhcPass c) data Pass = Parsed | Renamed | Typechecked deriving (Data) Is there any way to express that `pass` must be valid for each value of `Pass` in the following instance head? instance (p ~ GhcPass pass, OutputableBndrId p) => Outputable (HsIPBinds p) where This comes from a problem where setting each type family instance separately does not get picked up during instance resolution (and can't be, according to earlier questions by me on this) i.e. type instance XIPBinds (GhcPass 'Parsed) = NoExt type instance XIPBinds (GhcPass 'Renamed) = NoExt type instance XIPBinds (GhcPass 'Typechecked) = TcEvBinds it works fine for type instance XIPBinds (GhcPass _) = NoExt Alan ___ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs