I trying to create a type class Place which has String Coord [Int] , and a testData to store all the element into a list
data Place = Place String Coord [Int]
deriving (Ord,Eq,Show,Read)
data Coord = Cord Double Double
deriving (Ord ,Eq ,Show ,Read)
testData :: [Place]
testData = [ "London" Cord(51.5 ,-0.1) 0, 0, 5, 8, 8, 0, 0
"Cardiff" Cord(51.5 ,-3.2) 12, 8, 15, 0, 0, 0, 2
"Norwich" Cord(52.6 , 1.3) 0, 6, 5, 0, 0, 0, 3
"Birmingham" Cord(52.5 ,-1.9) 0, 2, 10, 7, 8, 2, 2
"Liverpool" Cord(53.4 ,-3.0) 8, 16, 20, 3, 4, 9, 2
"Hull" Cord(53.8 ,-0.3) 0, 6, 5, 0, 0, 0, 4
"Newcastle" Cord(55.0 ,-1.6) 0, 0, 8, 3, 6, 7, 5
"Belfast" Cord(54.6 ,-5.9) 10, 18, 14, 0, 6, 5, 2
"Glasgow" Cord(55.9 ,-4.3) 7, 5, 3, 0, 6, 5, 0
"Plymouth" Cord(50.4 ,-4.1) 4, 9, 0, 0, 0, 6, 5
"Aberdeen" Cord(57.1 ,-2.1) 0, 0, 6, 5, 8, 2, 0
"Stornoway" Cord(58.2 ,-6.4) 15, 6, 15, 0, 0, 4, 2
"Lerwick" Cord(60.2 ,-1.1) 8, 10, 5, 5, 0, 0, 3
"St Helier" Cord(49.2 ,-2.1) 0, 0, 0, 0, 6, 10, 0 ]
But it keep giving me this error
UP917725.hs:20:15: error:
• Couldn't match expected type ‘(Double -> Double -> Coord)
-> (Double, Double) -> Integer -> Place’
with actual type ‘[Char]’
• The function ‘"London"’ is applied to three arguments,
but its type ‘[Char]’ has none
In the expression: "London" Cord (51.5, - 0.1) 0
In the expression: ["London" Cord (51.5, - 0.1) 0, 0, 5, 8, ....]
|
20 | testData = [ "London" Cord(51.5 ,-0.1) 0, 0, 5, 8, 8, 0, 0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It keep saying that the actual type is Char, I also tried putting parenthesis with the int list aswell , So I probably think the error is somewhere around the definition of the datatype
Cord(x,y)should be(Cord x y)in your definition oftestData. The data constructor has kindDouble -> Double -> Coord, not(Double, Double) -> Coord.