我写了一个函数,它返回当前屏幕宽度为IO Integer(到目前为止)。在Haskell中连接字符串和IO整数
getScreenWidth:: IO Integer
getScreenWidth = do
(sx, sy, w, h) <- getScreenDim 0
return $ sx
现在,我想在屏幕宽度添加到字符串:
> magic_function :: IO Integer -> String -> ... magic output type
> magic_function = ... ? this is where i am stack at ? ...
我想魔术函数传递一个字符串,像“屏幕宽度:”我希望它添加当前屏幕宽度,以便我得到“屏幕宽度:1680”。我如何concat一个IO整数和一个普通的字符串?它是否与show
一起使用?
任何人都可以帮助我吗?
[Converting IO Int to Int]可能的重复(http://stackoverflow.com/questions/4235348/converting-io-int-to-int) – shang 2013-04-24 16:30:50
不,它不是重复的。我不想将IO类型转换为非IO类型,我想用字符串连接IO Int。我知道如何连接一个字符串和一个整数,虽然...... 可悲的是,提到的解决方案并不适合我。我是否必须将字符串转换为IO字符串?然后concat IO String和IO Integer? – user2316484 2013-04-24 16:34:28
@ user2316484如果你知道答案,你就知道答案。 – Carl 2013-04-24 17:05:03