Right, I have two functions. Both take exactly the same file input. run2D works perfectly, but oneR gives me the error Prelude.read: no parse. This confuses me as it’s my understanding that the no parse error usually means there’s a problem with the input file, which there obviously isn’t.
run2D :: [String] -> IO()
run2D [file,r] = do
thefile <- readFile file
let [v,e,f] = lines thefile
print(pullChi(eg2D (verticesMake (read v)) (read e) (read f) (read r)) (read r))
oneR :: [String] -> IO()
oneR [file] = do
thefile <- readFile file
let [v,e,f] = lines thefile
print(oneRobot (read v) (read e) (read f))
Here’s the contents of my input file
7
[[0,1],[1,2],[0,2],[1,3],[2,3],[1,4],[2,4],[0,6],[1,6],[1,5],[5,6],[4,5]]
[[0,1,2],[1,2,3],[1,2,4],[0,1,6],[1,5,6],[1,4,5]]
and my oneRobot function
oneRobot :: Integer -> [Integer] -> [Integer] -> Integer -- Takes #vertices, list of edges and robots and returns the euler characteristic where number of robots = 1
oneRobot v e f = v - genericLength(e) + genericLength(f)
The problem is: in your file, you have a representation of
[[Integer]]at the second and the third line.Change
oneRobotfunction signature and implementation to reflect this:or flatten your list of integer lists with
concatif it fits your task: