role annotation for newtype (partially?) ignored?
A constraint Coercible o (T a)
is ambiguous if the role of a
is representational (provided a
is not otherwise constrained, of course), but unambiguous if a
is a phantom type:
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RoleAnnotations #-}
module CoerceTest where
import Data.Coerce
type role A phantom
data A a = MkA Int
type role B representational
data B a = MkB Int
-- accepted by the type checker (as it should be)
fooA :: Coercible o (A a) => o -> ()
fooA _ = ()
-- rejected by the type checker (as it should be) with
-- "Couldn't match representation of type ‘a0’ with that of ‘a’"
-- fooB :: Coercible o (B a) => o -> ()
-- fooB _ = ()
However, for newtype
s something odd happens:
type role C representational
newtype C a = MkC Int
-- accepted by the type checker (but should not be)
fooC :: Coercible o (C a) => o -> ()
fooC _ = ()
Trac metadata
Trac field | Value |
---|---|
Version | 8.2.1-rc2 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |