I’m stuck on this problem and I’m very new to Haskell, I was trying to complete the first Euler problem with the following code:
main = putStrLn . show . sum $ [3,6..1000]:[5,10..1000]
And here’s the first part of the error:
euler/1.hs:1:19:
No instance for (Show t0) arising from a use of `show'
The type variable `t0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance Show Double -- Defined in `GHC.Float'
instance Show Float -- Defined in `GHC.Float'
instance (Integral a, Show a) => Show (GHC.Real.Ratio a)
-- Defined in `GHC.Real'
...plus 23 others
In the first argument of `(.)', namely `show'
In the second argument of `(.)', namely `show . sum'
In the expression: putStrLn . show . sum
What do you expect
[3,6..1000]:[5,10..1000]to do?x : xspreppeds an object to a list of objects. Here both arguments are lists of integers. Did you want++instead (concatenation).It needs to be said that your approach is not right, no matter what you expected
:to do. I’ll not expand on this in case you want to figure it out yourself.