[Haskell-beginners] Expected / Inferred mis-match and confused!
Daniel Fischer
daniel.is.fischer at googlemail.com
Thu Jun 9 18:55:06 CEST 2011
On Thursday 09 June 2011, 18:26:18, Sean Charles wrote:
> Here are the snippets of my code currently hurting my coding ulcer...
>
> routes :: [Record] -> IO ()
> routes legodata = do
> let all = foldl forwardRoutes M.empty legodata -- [Record]
> return ()
>
>
> forwardRoutes :: M.Map String [String] -> Record -> M.Map String
> [String]
> forwardRoutes map row =
> let key = row !! 0 in
> let val = row !! 1 in
> case lookup key map of
Ah, that needs to be M.lookup, without qualifying the call, it refers to
Prelude.lookup :: Eq a => a -> [(a,b)] -> Maybe b
> Nothing -> M.insert key [val] map
> Just routes -> M.insert key val:routes map
This needs parentheses, M.insert key (val:routes) map
>
> I have spent a long time searching and reading and trying to fathom it
> out from first principles but I cannot for the life of me figure out
> where '[(Field, b)]' is coming from!
Prelude.lookup vs. Data.Map.lookup
> I can smell Field in there because
> Record is typed as [Field], but a tuple? And what is 'b' ?
>
> The 'inferred type' matches what I thought it should be in the error
> message and I am right (I think) in stating that the 'expected type' is
> what it actually got from the code at compile time?!
>
> Help!
>
> :)
More information about the Beginners
mailing list