Skip to content

Unexpected representation-polymorphism error when using default signatures

I would expect the following program from @adamgundry to work, but it doesn't:

{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FunctionalDependencies #-}

module T23884 where

import Data.Kind
import GHC.Exts

type SetField :: forall {k} {r_rep} {a_rep} . k -> TYPE r_rep -> TYPE a_rep -> Constraint
class SetField x r a | x r -> a where
  modifyField :: (a -> a) -> r -> r

  setField :: a -> r -> r
  default setField :: (a_rep ~ LiftedRep) => a -> r -> r
  setField x = modifyField (\ _ -> x)
T23884.hs:16:3: error: [GHC-55287]
    The first pattern in the equation for `setField'
    does not have a fixed runtime representation.
    Its type is:
      a :: TYPE a_rep
   |
16 |   setField x = modifyField (\ _ -> x)
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

T23884.hs:16:36: error: [GHC-55287]
    * The binder of the lambda expression
      does not have a fixed runtime representation.
      Its type is:
        a0 :: TYPE a_rep0
      Cannot unify `a_rep' with the type variable `a_rep0'
      because the former is not a concrete `RuntimeRep'.
    * In the expression: x
      In the first argument of `modifyField', namely `(\ _ -> x)'
      In the expression: modifyField (\ _ -> x)
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information