Sadece F # öğrenmeye başladım ve e için Taylor serisinin ilk 10 şartını oluşturmaya ve değerlendirmeye çalışıyorum.'Float -> float' türü 'float' türüyle eşleşmiyor
let fact n = function
| 0 -> 1
| _ -> [1 .. n] |> List.reduce (*)
let taylor e =
let term n = (e ** n)/(fact n)
[1 .. 10]
|> List.map (term)
|> List.reduce (+)
**
operatör int
için çalışmıyor Bir hata nedeniyle yol açar: başlangıçta bunu hesaplamak için bu kodu yazdım. Açıkçası her şeyin düzgün çalışması için her şeyi float
'a dökmem gerekiyor. Yani:
let fact (n: float) = function
| 0.0 -> 1.0
| _ -> [1.0 .. n] |> List.reduce (*)
let taylor (e: float) =
let term (n: float) = (e ** n)/(fact n)
[1.0 .. 10.0]
|> List.map (term)
|> List.reduce (+)
:
EvaluatingEtotheX.fs(9,39): error FS0001: The type 'float -> float' does not match the type
'float'
EvaluatingEtotheX.fs(9,36): error FS0043: The type 'float -> float' does not match the type
'float'
(let term n = (e ** n)/(fact n)
olduğu Hattı 9).
Bu neden çalışmıyor ? Bu hata tam olarak ne anlama geliyor? Derleyici neden float
değerini veren ve gerçek bir float
değeri olmayan bir işlevi iletiyor? Sadece F'yi öğrenmeye başladığımı unutmayın, bu yüzden bu durumun neden bu işe yaramayacağını bilmiyorum.
Yukarı-oylama birisi bile niçin bir yorum bırakmadan onu aşağı olarak neden herhangi bir neden görmüyorum çünkü . –