[Haskell-cafe] Solved but strange error in type inference

Bardur Arantsson spam at scientician.net
Tue Jan 3 19:48:01 CET 2012


> 2012/1/3 Yucheng Zhang<yczhang89 at gmail.com>
>

(Hopefully being a little more explicit about this can help you 
understand where things are going wrong.)

[--snip--]
>
> legSome :: LegGram nt t s ->  nt ->  Either String ([t], s)

The 'nt' you see above

> legSome (LegGram g) ntV =
>   case Main.lookup ntV g of
>      Nothing ->  Left "No word accepted!"
>      Just l ->  let sg = legSome (LegGram (Main.delete ntV g))
>                    subsome :: [RRule nt t s] ->  Either String ([t], s)

... isn't the same as the 'nt' you see in this line, so it constrains 
'subsome' to a different type than the one you intended -- and indeed 
one which can't be unified with the inferred type. (Unless you use 
ScopedTypeVariables.)

As Brent suggested, you should probably pull the "subsome" function out 
into a top-level function in any case.

Cheers,




More information about the Haskell-Cafe mailing list