In F# why does my add function not add two floats
let add a b = a+b
(add 3 4) //returns 7
(add 3.5 5.5) //error
also please explain how type inference works in F#.
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have to make it inline.
The problem is that
+is an inline operator, so if your function add is not inline it will take the default overload which is for int.Have a look at this answer Use of `inline` in F#
When the function is declared inline, type inference will infer the static type constraints.
So now a and b could be any type that implement the static member (+) with that signature.