我正在尝试在Haskell中编写一个简单的函数,以返回居中的文本字符串,但我在确定要插入的填充量方面遇到了问题。 我有以下代码:
center padLength string = round ((padLength - (length string)) / 2)
这会导致以下错误:
No instance for (Fractional Int)
arising from a use of '/'
Possible fix: add an instance declaration for (Fractional Int)
In the first argument of 'round', namely
'((padLength - (length string)) / 2)'
In the expression: round ((padLength - (length string)) / 2)
In an equation for `center':
center padLength string = round ((padLength - (length string)) / 2)
我如何将Double类型(我认为)转换为Int类型?