对,我有两个功能。两者都采用完全相同的文件输入。run2D
完美运行,但oneR
给了我错误Prelude.read: no parse
。这让我感到困惑,因为我的理解是没有解析错误通常意味着输入文件存在问题,显然没有。
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))
这是我的输入文件的内容
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]]
和我的 oneRobot 功能
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)