这是我的代码:
open System
let rec gcd a b =
match b with
| x when x = 0 -> a
| _ -> gcd(b, a % b)
let result = gcd 15 10
[<EntryPoint>]
let main(args : string[]) =
printfn "result = %d" result
0
为什么我收到此代码的错误:
D:\datahub\Dropbox\development\myprojects\project-euler\Problem_5\problem_5.fs(6,16): error FS0001: Type mismatch. Expec
ting a
'a
but given a
int -> 'a
The resulting type would be infinite when unifying ''a' and 'int -> 'a'
答案 0 :(得分:3)
该示例尝试使用逗号分隔参数。在F#中,通过用空格分隔多个参数来提供给函数:
let rec gcd a b =
match b with
| x when x = 0 -> a
| _ -> gcd b (a % b)