如何在 F# 中简单地使字符串大写?

How to simple make string uppercase in F#?

尝试按照描述制作:

To convert a string to lowercase, you can call the String.ToLower() method

let makeUpperCase s = 
  s.ToUpper() 

得到结果

error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.

如果要调用作为参数传递给函数的值的成员,则必须向 F# 提供一些关于值类型的提示。最好的方法是使用类型注释:

let makeUpperCase (s:string) = 
  s.ToUpper() 

F# 编译器需要这个,因为它无法弄清楚 ToUpper 您试图调用什么方法,因为可能有许多 .NET 对象具有此名称的方法。