I keep getting a match type error. I've changed the syntax but cant seem to figure out the error
I'm trying to solve https://www.codewars.com/kata/560a4962c0cc5c2a16000068/train/haskell
eqSumPowDig :: Int -> Int -> [Int]
eqSumPowDig hmax po = [x | x<-[2..hmax], expo (show x) po]
where expo :: String -> Int -> Bool
expo b e = sum [(read n)^e | n<-b] == b
I get the error
• Couldn't match type ‘Char’ with ‘[Char]’
Expected type: String
Actual type: Char
• In the first argument of ‘read’, namely ‘n’
In the expression: (read n)
In the first argument of ‘sum’, namely ‘[(read n) | n <- b]’
|
6 | expo b e = (sum [(read n) | n<-b]) == b
| ^
CodePudding user response:
Because expo :: String -> Int -> Bool
b
is a String
. Then in the list comprehension [… | n<-b]
n becomes an element of b
which is a Char
. But read
expects a String