Skip to content

Instantly share code, notes, and snippets.

@aavogt
Last active August 29, 2015 14:21
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 aavogt/936b03b8a7875e690649 to your computer and use it in GitHub Desktop.
Save aavogt/936b03b8a7875e690649 to your computer and use it in GitHub Desktop.
roles are more restrictive (but not for newtype instance)
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Generic as G
import Data.Coerce
import Control.Monad.Primitive
import Foreign.C
data family MVec (v :: * -> *) :: * -> * -> *
newtype instance MVec V.Vector a b = VM_Vector (VM.MVector a b)
coerce_was_bad :: MVec V.Vector RealWorld Double -> MVec V.Vector RealWorld CDouble
coerce_was_bad = coerce
{- this error only happens if the MVec instance was a Data instance:
Could not coerce from ‘MVec V.Vector RealWorld Double’ to ‘MVec
V.Vector RealWorld CDouble’
because the third type argument of ‘MVec’ has role Nominal,
but the arguments ‘Double’ and ‘CDouble’ differ
arising from a use of ‘coerce’
In the expression: coerce
In an equation for ‘coerce_bad’: coerce_bad = coerce
-}
coerce_good :: G.Mutable V.Vector RealWorld Double -> G.Mutable V.Vector RealWorld CDouble
coerce_good = coerce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment