0
votes

Trying to run some haskell code, but it's not running. Gives me the error seen above

type Name = String
type Location = (Float,Float)
type RainfallFigures = [Int]
type Place = (Name,Location,RainfallFigures)

testData::[Place]
testData=[("London", (51.5, -0.1), [0, 0, 5, 8, 8, 0, 0]),("Cardiff", (51.5 , -3.2),[12, 8, 15, 0, 0, 0, 2])]

rtnNames::[Place] -> [Place]
rtnNames x=x 


demo :: Int -> IO ()
demo 1 = rtnNames testData

Error occurs on the last line demo 1 = rtnNames testData I'm trying to get rtnNames to just return the test data itself for now as a first hurdle

1

1 Answers

2
votes

The problem is that your signature

demo :: Int -> IO ()

indicates that demo should return an IO action of type IO (). However, your implementation returns rtnNames testData. Since the implementation of rtnNames just returns its argument, this is equivalent to just testData. That's a problem, though, since testData is a [Place], not an IO (). Perhaps you want to print the list of names? That would look like this:

demo 1 = print testData

which I expect will compile.

There are, however, some deeper design issues with your code. You're using a number of types that would probably be better as newtypes. newtype lets you extend the type checker to make sure that a particular [Int] is actually a RainfallFigures, and not just any old list of numbers.

Your rtnNames function is also concerning, since it doesn't do anything. There's nothing intrinsically wrong with a function that does nothing, and in fact it can be quite useful, which is why it exists out of the box, viz. id with type a -> a. rtnNames is just a specialization of id, but from the context in which you use it, I suspect it isn't meant to be.