How does GHC interpret `foldl + 0 [1,2,3]` (without parentheses around +)?

Viewed 111

One thing that got me stuck early when learning Haskell was the difference between foldl + and foldl (+).

Prelude> :t foldl + 0 [1,2,3]
  :: (Num t1, Num ((b -> a -> b) -> b -> t a -> b),
      Num ([t1] -> (b -> a -> b) -> b -> t a -> b), Foldable t) =>
     (b -> a -> b) -> b -> t a -> b

vs

Prelude> :t foldl (+) 0 [1,2,3]
foldl (+) 0 [1,2,3] :: Num b => b

How does Haskell / GHC derive the type of foldl + 0 [1,2,3]? How can I understand why it expands to this giant type?

3 Answers
Related