我是一個Haskell noob,目前只能用它來配置xmonad。如何將Haskell System.Directory getHomeDirectory轉換爲常規字符串?
我想把我的配置放入一個git repo中,因爲我想不必硬編碼我的主目錄來獲取我的圖標。
我簽出 http://www.haskell.org/haskellwiki/How_to_get_rid_of_IO 但我太無知,無法理解它。
hd h = h =<< getHomeDirectory
getIcon::String -> String
getIcon out = ("^i("++hd++".xmonad/dzen2/"++out)
這實際上可能嗎?如果是這樣,怎麼樣? 我不想在目錄上進行操作,我只是想將路徑作爲一個字符串來使用,並且會導致我死亡。
錯誤是:
Couldn't match expected type `[Char]' with actual type `(FilePath -> IO b0) -> IO b0' In the first argument of `(++)', namely `hd' In the second argument of `(++)', namely `hd ++ ".xmonad/dzen2/" ++ out' In the expression: ("^i(" ++ hd ++ ".xmonad/dzen2/" ++ out)
在我看來就像是不會被刪除的IO單子都沒有。
更新: 好的。我將學習如何適應IO規則,直到那時我會保持硬編碼並用一個腳本來克隆配置文件,該腳本將替換適當的位。
是的,我知道IO位,這是給我的麻煩。我需要返回的IO字符串作爲常規字符串,因爲這就是配置所期望的。不過,你的代碼確實幫助我理解了別的東西。做,並返回$ – Erius 2013-03-12 15:12:00
@Erius沒有(安全)Haskell函數的類型'IO字符串 - >字符串'。 'IO'在'IO'中停滯了。 – 2013-03-12 15:50:07