Skip to content
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

Use withDict instead of unsafeCoerce to implement bindIP #165

Open
RyanGlScott opened this issue May 13, 2022 · 0 comments · May be fixed by #166
Open

Use withDict instead of unsafeCoerce to implement bindIP #165

RyanGlScott opened this issue May 13, 2022 · 0 comments · May be fixed by #166

Comments

@RyanGlScott
Copy link
Collaborator

Currently, bindIP is implemented using unsafeCoerce:

bindIP :: forall name a r. a -> (IP name a => r) -> r
bindIP val k = (unsafeCoerce (MagicIP @name k) :: a -> r) val

Using GHC 9.4 or later, however, we can instead implement this using withDict. This is safer to use, results in cleaner Core, and will be future-proof against future changes to "newtype classes" that are being considered here.

See goldfirere/singletons#490 and ekmett/reflection#44 for related issues.

@RyanGlScott RyanGlScott mentioned this issue May 13, 2022
4 tasks
RyanGlScott added a commit that referenced this issue May 14, 2022
Instead of `unsafeCoerce`, we can use the more recent `withDict` primitive
from `GHC.Exts`. Among other benefits, this is more likely to be future-proof
against possible changes to GHC's representation of "newtype classes" in the
future.

Fixes #165.
@RyanGlScott RyanGlScott linked a pull request May 14, 2022 that will close this issue
RyanGlScott added a commit that referenced this issue May 14, 2022
Instead of `unsafeCoerce`, we can use the more recent `withDict` primitive
from `GHC.Exts`. Among other benefits, this is more likely to be future-proof
against possible changes to GHC's representation of "newtype classes" in the
future.

Fixes #165.
RyanGlScott added a commit that referenced this issue Jun 26, 2022
Instead of `unsafeCoerce`, we can use the more recent `withDict` primitive
from `GHC.Exts`. Among other benefits, this is more likely to be future-proof
against possible changes to GHC's representation of "newtype classes" in the
future.

Fixes #165.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant