0
我試圖創建一個函數來總結SML中的一個整數的數字,但我得到以下錯誤。使用SML的整數中的數字總和
Error: operator and operand don't agree [overload conflict]
operator domain: real * real
operand: [* ty] * [* ty]
in expression:
n/(d * 10)
我試圖將變量轉換爲真實的,但它沒有工作。另外我不明白爲什麼我得到這個錯誤。在SML中不可能使用*和/或int和real等運算符?
的代碼如下:
fun sumDigits (n) =
if n < 10 then n
else
let
val d = 10
in
n mod d + sumDigits(trunc(n/(d*10)))
end