[Haskell-beginners] Infinite type ... or 'not enough type arguments'...

Daniel Fischer daniel.is.fischer at googlemail.com
Thu Jun 9 14:27:14 CEST 2011

On Thursday 09 June 2011, 13:57:47, Sean Charles wrote:
> Further to my recent attempts to scan a CSV file and build a map, I now
> have a foldl calling this with an empty map:
> --forwardRoutes :: M.Map String [String] -> Record -> M.Map
> forwardRoutes map row =
>    case lookup map (row!!0) of
>      Nothing -> M.insert (row!!0) [(row !! 1)] map
>      Just routes -> M.insert (row!!0) (row!!1):routes map

Needs parentheses

    Just routes -> M.insert (row!!0) ((row!!1):routes) map

Without, it's parsed (M.insert (row!!0) (row!!1)) : (routes map)

I'm not in the mood to figure out how the type inference reaches its 
conclusion, I can tell however, that it started inferring the type with the 

> With the type declaration commented out I get this:
> scread.hs:102:46:
>      Occurs check: cannot construct the infinite type:
>        a = M.Map [(a, b)] [[(a, b)]]
>        Expected type: M.Map [(a, b)] [[(a, b)]]
>        Inferred type: a
>      In the third argument of `M.insert', namely `map'
>      In the expression: M.insert (row !! 0) [(row !! 1)] map
> and with it 'in#' i get this error instead...
> scread.hs:99:52:
>      `M.Map' is not applied to enough type arguments
>      Expected kind `?', but `M.Map' has kind `* -> * -> *'
>      In the type signature for `forwardRoutes':
>        forwardRoutes :: M.Map String [String] -> Record -> M.Map

You forgot the type arguments of Map in the result type.

M.Map is a type constructor taking two arguments, but type arguments of 
(->) must be fully applied type constructors

> Can anybody help me to understand both problems. I thought I had
> declared the type signature of forwardRoutes correctly but obv. not! LOL
> I have seen information that says the "infinite error" message can be
> cured by supplying types so I did......
> Thanks again.
> Sean

More information about the Beginners mailing list