函数返回类型不明确的问题

函数返回类型不明确的问题

本文介绍了函数返回类型不明确的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下相当简单的F#函数:

I have the following rather simple F# function:

let FormatValue (formatProvider : IFormatProvider) valueSuffix value =
    match value > Convert.ToDecimal(valueSuffix.MinimumValueRequired) with
    | true -> let normalizedValue = Convert.ToDecimal(value) / Convert.ToDecimal((Math.Pow(10., Convert.ToDouble(valueSuffix.PowerOfTen)))) in
                  string.Format("{0}{1}", normalizedValue.ToString(valueSuffix.Format, formatProvider), valueSuffix.Text)
    | false -> ""

返回类型正确地推断为string,但是我在true分支的string.Format处得到一个错误标记,表示类型<'a> -> string与类型ValueSuffix不兼容.我发现这特别令人惊讶,因为可以正确推断所有其他类型,尤其是在函数中没有其他<'a>出现.

The return type is correctly inferred as string, however I get an error marker at string.Format in the true branch, saying the type <'a> -> string is not compatible with type ValueSuffix. I find this especially surprising as all other types are inferred correctly, and in particular there is no other occurrence of <'a> in the function.

我在做什么和/或理解错误?

What am I doing and/or understanding wrong?

推荐答案

问题是string.Format在F#代码中无效.

The issue was that string.Format is not valid in F# code.

您需要使用

System.String.Format

open System
.....
String.Format

(区别是string

这篇关于函数返回类型不明确的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 23:17