0

if i try to run this msall little code:

module Problem14 where 

duplicate = foldl (\acc x -> acc ++ [x,x]) []

I get the following error message by GHCi:

*Ambiguous type variable `t0' arising from a use of `foldl'
prevents the constraint `(Foldable t0)' from being solved.
Relevant bindings include*

Why is GHCi giving me that message?

duplode
  • 33,731
  • 7
  • 79
  • 150
Kyrill96
  • 39
  • 4
  • Why don't you provide the "Relevant bindings"? – Willem Van Onsem Jan 23 '17 at 20:06
  • 3
    You need to provide a type signature for `duplicate`, something like `[a] -> [a]` or `Foldable t => t a -> [a]` will work. GHC doesn't want to default anything for you so it tells you that the type signature is ambiguous. – bheklilr Jan 23 '17 at 20:11
  • Did you try searching SO for this error message? If so what is confusing you about the answers to those other questions? – jberryman Jan 23 '17 at 20:17
  • Thanks! I didnt know exactly what is meant with relevant bindings, now i know. – Kyrill96 Jan 23 '17 at 20:36

0 Answers0