我想做一個簡單的函數來在Haskell中返回一個居中的字符串文本,但我遇到麻煩只是找到多少填充插入任何一方。我有這樣的: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)
我怎麼能(主要)由雙(我認爲)爲int轉換?
爲什麼需要'?我對Haskell有點新奇 –
我已經將這些信息添加到我的回答:) – ehird