-
-
Save expipiplus1/a30476ad9aabbbf17e937bf7a5c3bb23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE ConstrainedClassMethods #-} | |
module A where | |
class C m where | |
foo :: C m => m () | |
newtype N m a = N (m a) | |
deriving C |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ghc --version | |
The Glorious Glasgow Haskell Compilation System, version 8.0.1 | |
$ ghc -ddump-deriv A.hs | |
[1 of 1] Compiling A ( A.hs, A.o ) | |
==================== Derived instances ==================== | |
Derived instances: | |
instance A.C m_aNK => A.C (A.N m_aNK) where | |
A.foo = GHC.Prim.coerce (A.foo :: m_ap1 ()) :: A.N m_ap1 () | |
GHC.Generics representation types: | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ghc --version | |
The Glorious Glasgow Haskell Compilation System, version 8.0.2 | |
$ ghc A.hs | |
[1 of 1] Compiling A ( A.hs, A.o ) | |
A.hs:10:12: error: | |
• Couldn't match type ‘m’ with ‘N m’ | |
arising from the coercion of the method ‘foo’ | |
from type ‘C m => m ()’ to type ‘C (N m) => N m ()’ | |
‘m’ is a rigid type variable bound by | |
the deriving clause for ‘C (N m)’ at A.hs:10:12 | |
• When deriving the instance for (C (N m)) | |
$ ghc -ddump-deriv -fdefer-type-errors A.hs | |
[1 of 1] Compiling A ( A.hs, A.o ) | |
==================== Derived instances ==================== | |
Derived instances: | |
instance A.C m_awm => A.C (A.N m_awm) where | |
A.foo | |
= GHC.Prim.coerce | |
@(A.C m_ap0 => m_ap0 ()) @(A.C (A.N m_ap0) => A.N m_ap0 ()) A.foo | |
GHC.Generics representation types: | |
A.hs:11:12: warning: [-Wdeferred-type-errors] | |
• Couldn't match type ‘m’ with ‘N m’ | |
arising from a use of ‘GHC.Prim.coerce’ | |
‘m’ is a rigid type variable bound by | |
the instance declaration at A.hs:11:12 | |
• In the expression: | |
GHC.Prim.coerce @(C m => m ()) @(C (N m) => N m ()) foo | |
In an equation for ‘foo’: | |
foo = GHC.Prim.coerce @(C m => m ()) @(C (N m) => N m ()) foo | |
When typechecking the code for ‘foo’ | |
in a derived instance for ‘C (N m)’: | |
To see the code I am typechecking, use -ddump-deriv | |
In the instance declaration for ‘C (N m)’ | |
• Relevant bindings include foo :: N m () (bound at A.hs:11:12) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment