Skip to content

Heterogeneous coercions

I noticed something annoying:

import GHC.Generics
import Data.Coerce
fun :: forall j k (a :: j) (b :: k). V1 a -> V1 b
fun = coerce

gives me

    • Couldn't match type ‘j’ with ‘k’ arising from a use of ‘coerce’
      ‘j’ is a rigid type variable bound by
        the type signature for:
          fun :: forall j k (a :: j) (b :: k). V1 a -> V1 b
        at <interactive>:8:1-49
      ‘k’ is a rigid type variable bound by
        the type signature for:
          fun :: forall j k (a :: j) (b :: k). V1 a -> V1 b
        at <interactive>:8:1-49
    • In the expression: coerce
      In an equation for ‘fun’: fun = coerce
    • Relevant bindings include
        fun :: V1 a -> V1 b (bound at <interactive>:8:52)

Ugh. Now obviously, this micro-example is easily handled by writing

fun = \case

instead, but in more interesting situations that's not an option.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information