Skip to content

Instantly share code, notes, and snippets.

@kosmikus
Created April 20, 2017 13:59
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 kosmikus/3660d79bdab60eb6e7e32b5a30dd89a2 to your computer and use it in GitHub Desktop.
Save kosmikus/3660d79bdab60eb6e7e32b5a30dd89a2 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RoleAnnotations #-}
module CoerceTest where
import Data.Coerce
type role A phantom
data A a = MkA Int
-- works (CORRECT)
fooA :: Coercible o (A a) => o -> ()
fooA _ = ()
type role B representational
data B a = MkB Int
{-
-- does not work (CORRECT)
fooB :: Coercible o (B a) => o -> ()
fooB _ = ()
-}
type role C representational
newtype C a = MkC Int
-- works, but should not
fooC :: Coercible o (C a) => o -> ()
fooC _ = ()
newtype D a = MkD a
{-
-- does not work (CORRECT)
fooD :: Coercible o (D a) => o -> ()
fooD _ = ()
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment