Skip to content

Coercing between constraints of newtypes

This doesn't work

{-# Language ConstraintKinds #-}
{-# Language GADTs #-}

import Data.Coerce

newtype USD = USD Int

data Dict c where
  Dict :: c => Dict c

num :: Dict (Num Int) -> Dict (Num USD)
num = coerce

but this does

data NUM a = NUM (a -> a -> a)

num' :: NUM Int -> NUM USD
num' = coerce

is this a fundamental limitation?

Trac metadata
Trac field Value
Version 8.2.1
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information