This is a follow up question to this one: Syntax confusion (do block) So, please see it for more information and the original code. After I’ve been kindly helped, I’ve discovered yet another problem, which I suspect to be caused by “overloaded strings” whatever that means.
It looks like the simple-mysql library does something to string literal, so that they are understood by the parser to be of type Query. This is also what their examples demonstrate. However, all examples use unrealistically short queries, where you don’t need to wrap the code. I do need to wrap it, and string concatenation causes the resulting string to not to be recognized as of type Query. Why did anyone decide that this kind of approach will be useful is beyond my comprehension, I just want to be done with this assignment…
So, please, if you happen to know, kindly advise what to do / how can I have string converted to query.
The problematic code and the error are shown below:
-- Couldn't match expected type `Query' against inferred type `[a]'
-- In the expression:
-- "select count('*')"
-- ++ "from table"
-- ++ "where ((acquisition_date <= ?)"
-- ++ "and ((sale_date is null) or " ++ "(sale_date < ?)))"
-- In the definition of `countGoodsQuery':
-- countGoodsQuery = "select count('*')"
-- ++ "from table"
-- ++ "where ((acquisition_date <= ?)"
-- ++ "and ((sale_date is null) or " ++ "(sale_date < ?)))"
countGoodsQuery :: Query
countGoodsQuery = "select count('*')" ++
"from table" ++
"where ((acquisition_date <= ?)" ++
"and ((sale_date is null) or " ++
"(sale_date < ?)))"
You can wrap a string literal across multiple lines by adding a backslash at the end of the line, and another backslash where the string should continue, so you can write your example like this: