內部的ExceptT String IO()
單子轉換和應用性也許
我有一個產生ReaderT像這樣一個功能的DO塊:
type UDCEnv = (AWS.Env, Bool)
uploadVersionFilesToCaches :: S3.BucketName
-> FilePath
-> [GitRepoNameAndVersion]
-> ReaderT UDCEnv IO()
我只是這麼碰巧有一個Maybe FilePath
所以我創造我ReaderT像這樣:
let maybeReader :: Maybe (ReaderT UDCEnv IO()) =
uploadVersionFilesToCaches s3BucketName <$> maybeFilePath <*> Just gitRepoNamesAndVersions
我甚至可以運行ReaderT像這樣:
let maybeIO :: Maybe (IO()) =
runReaderT <$> maybeReader <*> Just (env, shouldIgnoreLocalCache, verbose)
只要我使用let
表達式,一切正常。當我在表達降let
上述實際嘗試有表達式計算應用型變類型爲ExceptT String IO FilePath
而不是Maybe
我忽略被標記的部分由...
:
f :: ... -> ExceptT String IO()
f ... = do
...
runReaderT <$> maybeReader <*> Just (env, shouldIgnoreLocalCache, verbose) -- Error here
undefined
主要生產
Couldn't match type ‘IO()’ with ‘()’
Expected type: ReaderT UDCEnv IO() -> UDCEnv ->()
Actual type: ReaderT UDCEnv IO() -> UDCEnv -> IO()
In the first argument of ‘(<$>)’, namely ‘runReaderT’
In the first argument of ‘(<*>)’, namely
‘runReaderT
<$>
(uploadVersionFilesToCaches s3BucketName <$> maybeFilePath
<*> Just gitRepoNamesAndVersions)’
/Users/blender/Code/Personal/Haskell/Rome-Public/src/Lib.hs: 82, 73
Couldn't match type ‘Maybe’ with ‘ExceptT String IO’
Expected type: ExceptT String IO FilePath
Actual type: Maybe FilePath
In the second argument of ‘(<$>)’, namely ‘maybeFilePath’
In the first argument of ‘(<*>)’, namely
‘uploadVersionFilesToCaches s3BucketName <$> maybeFilePath’
我認爲第一個錯誤是因爲我在某處丟失了一些liftIO
。
但是我不知道如何處理誤解的應用程序。
我可以對Maybe的案例分析,而不是使用Applicative,但我真的不想使用Applicative。
從錯誤判斷,您缺少'return',而不是'liftIO'。 – arrowd
@arrowd很可能,但不幸的是,這對我的應用問題沒有幫助。也許這不是正確的做法? – tmpz
您可以在runreaderT ...表達式實際出現的地方包含代碼嗎?最有可能的是,它被用在do-block中,Haskell試圖將它輸入爲「ExceptT String IO()」而不是'Maybe(IO())'。這最終會解釋這兩個錯誤,因爲'Maybe'不是'ExceptT String IO',而'()'不是'IO()'。這可能與添加標準的Maybe-to-ExceptT接口一樣簡單。 –