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

Yucheng Zhang yczhang89 at gmail.com
Tue Jan 3 11:50:39 CET 2012

On Tue, Jan 3, 2012 at 6:44 PM, Brandon Allbery <allbery.b at gmail.com> wrote:
> On Tue, Jan 3, 2012 at 05:17, Yucheng Zhang <yczhang89 at gmail.com> wrote:
>> subsome :: [RRule nt t s] -> Either String ([t], s)
>> It seems to me that the compiler is not sure the two 'nt' are equal.
>> The ScopedTypeVariables can make the compiler believe they are equal.
> But ScopedTypeVariables is enabled already.

Sorry, I meant actually using ScopedTypeVariables as in the first function,
which compiles well:

legSome :: LegGram nt t s -> nt -> Either String ([t], s)
--         ^^^^^^^^^^^^^^
--            isn't this redundant?
--                    vvvvvvvvvvvvvv
legSome ((LegGram g)::LegGram nt t s) ntV =
  case M.lookup ntV g of
    Nothing -> Left "No word accepted!"
    Just l -> let sg = legSome (LegGram (M.delete ntV g))
                  subsome :: [RRule nt t s] -> Either String ([t], s)
                  subsome [] = Left "No word accepted!"
                  subsome ((r,sem):l) =
                    let makeWord [] = Right ([],[])
                        makeWord ((NT nnt):ll) =
                          do (m, ss) <- sg nnt
                             (mm, sss) <- makeWord ll
                             return (m++mm, ss:sss)
                        makeWord ((T tt):ll) =
                          do (mm, sss) <- makeWord ll
                             return (tt:mm, sss)
                   case makeWord r of
                     Right (ll, mm) -> Right (ll, sem mm)
                     Left err -> subsome l
              in subsome l

More information about the Haskell-Cafe mailing list