![](/img/trans.png)
[英]How to fix missing instance of IO for a function constrained on MonadReader and MonadIO?
[英]How do I run this method with MonadReader and MonadIO?
我正在關注Haskell中讀者monad的這篇文章 。
它從定義開始:
load :: Config -> String -> IO String
load config x -> readFile (config ++ x)
其中Config是String的類型別名,它表示目錄名稱。
該方法旨在在屏幕上顯示文件的內容,例如“./myFile.txt”。
我從ghci運行這個方法:
load "./" "myFile.txt"
第二個例子介紹了讀者monad:
load :: (MonadReader Config m, MonadIO m) => String -> m String
load x = do
config <- ask
liftIO $ readFile (config ++ x)
問題是: 如何從ghci運行它 ?
我嘗試過這樣的事情:
(runReader load "myFile.txt") "./"
但沒有快樂。
加載./myFile.txt的命令是什么?
runReaderT (load "myFile.txt") "./" :: IO String
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.