Skip to content

Misleading (polymorphic) multiplicativity error

Assume Multi.hs:

{-# LANGUAGE LinearTypes #-}

foo :: a %m -> a
foo = bar

bar :: a -> a
bar x = x

If I start GHCi 9.2 with just ghci Multi.hs I get misleading error:

    • Couldn't match type ‘'Many’ with ‘'Many’
      Expected: a -> a
        Actual: a -> a
      ‘m’ is a rigid type variable bound by
        the type signature for:
          foo :: forall a. a -> a
        at Multi.hs:3:1-16
    • In the expression: bar
      In an equation for ‘foo’: foo = bar
    • Relevant bindings include foo :: a -> a (bound at Multi.hs:4:1)
  |
4 | foo = bar
  |     

Some multiplicativity printing logic is wrong, as if I add -XLinearTypes at the start of the interpreter already, ghci -XLinearTypes Multi.hs, the correct error is printed:

Multi.hs:4:7: error:
    • Couldn't match type ‘m’ with ‘'Many’
      Expected: a %m -> a
        Actual: a -> a
      ‘m’ is a rigid type variable bound by
        the type signature for:
          foo :: forall a (m :: GHC.Types.Multiplicity). a %m -> a
        at Multi.hs:3:1-16
    • In the expression: bar
      In an equation for ‘foo’: foo = bar
    • Relevant bindings include
        foo :: a %m -> a (bound at Multi.hs:4:1)
  |
4 | foo = bar
  |       ^^^
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information