Reputation: 79
So I'm trying to go through a list of films and output the title of each film, the compiler is saying that is couldn't match type [Char]
with Char
.
The thing is I want [Char]
(A string) and not Char
?? I'm confused as to why it wants a character and not a string?
fas:: [Film] -> String
fas database = [title x | x <- database]
test.hs:55:27: error:
• Couldn't match type ‘[Char]’ with ‘Char’
Expected type: Char
Actual type: String
• In the expression: title x
In the expression: [title x | x <- database]
In an equation for ‘fas’:
fas database = [title x | x <- database]
Any help would be greatly appreciated, I've probably worded this poorly which hasn't helped me when trying to search other people have the same problem :/
regards, a novice
Upvotes: 1
Views: 354
Reputation: 476709
If I understand what you want to do correctly, the signature should be:
fas:: [Film] -> [String]
Indeed, a list of strings.
Why? Because you map every film to its title. Now since a title is a String
, the result is a list of String
s.
The compiler is actually complaining in the other way than you interpret it: since type String = [Char]
, you wrote implicitly:
fas :: [Film] -> [Char] -- incorrect
whereas it should be:
fas :: [Film] -> [[Char]]
Upvotes: 3