Skip to content
Latchkey

Haskell GHC "Couldn't match expected type" in CI

GHC type-checked an expression and the type it inferred does not match the type the surrounding code requires. The error names the expected and actual types and points at the offending expression.

What this error means

Compilation fails with "Couldn't match expected type 'X' with actual type 'Y'", often listing "In the expression:" and "In an equation for ...".

Haskell
src/Lib.hs:8:14: error:
    * Couldn't match expected type 'Int' with actual type 'String'
    * In the first argument of 'succ', namely 'name'
      In the expression: succ name

Common causes

An expression has the wrong type for its context

A value of one type is used where another is required, with no conversion, so the types do not unify.

A signature or dependency change shifted a type

A changed function signature, or a dependency version with a different type, made previously matching code mismatch.

How to fix it

Convert or correct the mismatched value

  1. Read the expected versus actual type GHC reports.
  2. Convert the value (for example with read, show, fromIntegral) or fix the call so the types unify.
  3. Recompile to confirm the error clears.
Haskell
-- convert the String to an Int before succ
succ (read name :: Int)

Reconcile a changed signature or dependency

If a dependency changed a type, pin a compatible version or update the call sites to the new signature.

How to prevent it

  • Add explicit type signatures so mismatches surface early.
  • Pin dependency versions so exported types stay stable.
  • Run the type checker locally before pushing.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →