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 nameCommon 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
- Read the expected versus actual type GHC reports.
- Convert the value (for example with
read,show,fromIntegral) or fix the call so the types unify. - 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
Haskell GHC "Could not find module" in CIFix GHC "Could not find module X" in CI - the module is not exposed by any package in scope, usually a missin…
Haskell GHC out of memory in CIFix GHC "out of memory" / "ghc: failed to allocate" / killed by the OOM killer in CI - compilation exceeded t…
Haskell cabal "is a member of the hidden package" / build-depends in CIFix GHC "Could not load module ... it is a member of the hidden package X" in CI - the package providing a mo…