Skip to content

Instantly share code, notes, and snippets.

@expipiplus1
Last active October 27, 2016 11:30
Show Gist options
  • Save expipiplus1/a30476ad9aabbbf17e937bf7a5c3bb23 to your computer and use it in GitHub Desktop.
Save expipiplus1/a30476ad9aabbbf17e937bf7a5c3bb23 to your computer and use it in GitHub Desktop.
{-# 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
$ 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:
$ 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