Skip to content

Linear types and -fdefer-type-errors

Linear types combined with -fdefer-type-errors show a poor error message.

ghci> :set -XLinearTypes
ghci> ap :: (a -> b) -> a %m -> b; ap f x = f x

<interactive>:2:35: error:
    • Couldn't match type ‘m’ with ‘'Many’
        arising from multiplicity of ‘x’
      ‘m’ is a rigid type variable bound by
        the type signature for:
          ap :: forall a b (m :: GHC.Types.Multiplicity).
                (a -> b) -> a %m -> b
        at <interactive>:2:1-27
    • In an equation for ‘ap’: ap f x = f x
    • Relevant bindings include
        ap :: (a -> b) -> a %m -> b (bound at <interactive>:2:30)
ghci> :set -fdefer-type-errors
ghci> ap :: (a -> b) -> a %m -> b; ap f x = f x

<interactive>:4:30: error:
    Multiplicity coercions are currently not supported (see GHC #19517)

<interactive>:4:30: error:
    Multiplicity coercions are currently not supported (see GHC #19517)

The error message is technically correct, but -fdefer-type-errors downgrades the type mismatch to a warning. The warning is not shown, while it contains important information.

Until #19517 is done, when -fdefer-type-errors is on, we should compile multiplicity coercions to runtime errors and convert the error to a warning.

Also make the message more user-friendly.

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