Skip to content

Instantly share code, notes, and snippets.

@lspitzner
Created October 10, 2018 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lspitzner/2e3f0257f390bd9a97016cdc96820d5f to your computer and use it in GitHub Desktop.
Save lspitzner/2e3f0257f390bd9a97016cdc96820d5f to your computer and use it in GitHub Desktop.
GeneralizedNewtypeDeriving and roles
class A a where
a :: Monad m => a -> m a
instance A Int where
a = pure
newtype MyNewtype = MyNewtype Int deriving A
-- ^
-- error:
-- • Couldn't match representation of type ‘m Int’
-- with that of ‘m MyNewtype’
-- arising from the coercion of the method ‘a’
-- from type ‘forall (m :: * -> *). Monad m => Int -> m Int’
-- to type ‘forall (m :: * -> *). Monad m => MyNewtype -> m MyNewtype’
-- NB: We cannot know what roles the parameters to ‘m’ have;
-- we must assume that the role is nominal
-- • When deriving the instance for (A MyNewtype)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment