haskell - Why does GHC produce an equality constraint error rather than a type match error here? -



haskell - Why does GHC produce an equality constraint error rather than a type match error here? -

following this question, i'm not sure why these 2 code snippets produce different errors:

f :: -> b f x = x -- couldn't match expected type `b' actual type `a' -- in expression: x g :: monad m => -> m b g x = homecoming x -- not deduce (a ~ b) context (monad m) -- in first argument of `return', namely `x'.

what rule giving rising behavior?

it's not readable, familiar standard haskell; equality constraint (a ~ b) requires language extension.

note that, chi pointed out, mere presence of constraint triggers constraint error:

class c h :: c => -> b h x = x -- not deduce...

(an empty constraint, () => -> b, gives match not constraint error.)

i don't think there's shorter reply digging ghc internals understand why.

if run ghc -ddump-tc-trace switch, can quite lengthy log of typechecking process. in particular, if run on code:

f :: -> b f x = x class c h :: c c => c -> d h x = x

you can see typechecking a vs b, , typechecking c vs d progresses same way in both cases, culminating in next 2 unsolved constraints (output ghc 7.8.2):

tryreporters { [[w] cobox_ajh :: c ~ d (cnoncanonical)] ... tryreporters { [[w] cobox_ajk :: ~ b (cnoncanonical)]

by next rabbit hole bit more in tcerrors, can see equalities on skolems, tryreporters gets creating error message via mismatchorcnd, has explicit special case empty contexts:

mismatchorcnd :: reporterrctxt -> ct -> maybe swapflag -> tctype -> tctype -> sdoc -- if oriented ty1 actual, ty2 expected mismatchorcnd ctxt ct oriented ty1 ty2 | null givens || (isrigid ty1 && isrigid ty2) || isgivenct ct -- if equality unconditionally insoluble -- or there no context, don't study context = mismatchmsg oriented ty1 ty2 | otherwise = couldnotdeduce givens ([mktceqpred ty1 ty2], orig)

haskell compiler-errors ghc

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -