我是一个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