Created
October 10, 2018 18:32
-
-
Save lspitzner/2e3f0257f390bd9a97016cdc96820d5f to your computer and use it in GitHub Desktop.
GeneralizedNewtypeDeriving and roles
This file contains 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
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