这是我得到的类型错误,其次是相关代码.这可能是因为函数组合的使用不正确,如果是这样,我想解释一下如何解决这个问题.如果这是别的什么,我也想谈谈这个.
frameworkDaemon.lhs:125:5:
Couldn't match expected type `IO ()' with actual type `a0 -> c0'
In the expression: popJobState . popProcessConfig . readJobFile
In an equation for `makeJobState':
makeJobState world
= popJobState . popProcessConfig . readJobFile
where
readJobFile
= do { let ...;
.... }
where
getFileContents (x : xs) = readFile (ixiaRoot ++ "/" ++ (show x))
popProcessConfig = undefined
popJobState = undefined
Run Code Online (Sandbox Code Playgroud)
失败,模块加载:无.
makeJobState :: JobState -> IO ()
makeJobState world =
popJobState . popProcessConfig . readJobFile -- f .g . h -> f(g(h))
where readJobFile = do
let directoryPath = ixiaRoot ++ "/jobs"
processedPath = map (directoryPath </>) . filter (`notElem` [".",".."])
jobFileNames <- processedPath <$> getDirectoryContents directoryPath
let numStrings = map (last . splitOn "/") jobFileNames
sortJobNumbers = map read numStrings :: [Int]
getFileContents $ sort $ sortJobNumbers
where getFileContents (x:xs) = readFile (ixiaRoot ++ "/" ++ (show x))
popProcessConfig = undefined
popJobState = undefined
Run Code Online (Sandbox Code Playgroud)
-- f .g . h -> f(g(h))
Run Code Online (Sandbox Code Playgroud)
f . g . h是不是等同于f(g(h)),这是相当于\x -> f(g(h x)),因此h需要一个功能,但readJobFile(这是h在你的例子)是IO ().这就是错误消息抱怨期望你给它一个功能的原因IO ().