Type family constraints

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Type family constraints

Alan & Kim Zimmerman
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Type family constraints

Richard Eisenberg-4


On Apr 23, 2018, at 6:56 AM, Alan & Kim Zimmerman <[hidden email]> 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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Type family constraints

Alan & Kim Zimmerman
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

RE: Type family constraints

GHC - devs mailing list
In reply to this post by Alan & Kim Zimmerman

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 <[hidden email]> On Behalf Of Alan & Kim Zimmerman
Sent: 23 April 2018 11:57
To: ghc-devs <[hidden email]>
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs