5

In Visual Studio 2015:

let myFunction (``string`` : string) =
    "\"Quoted string\"" |> (Regex "\"[^\"]*\"").Match |> string

let myOtherFunction (str : string) =
    "\"Quoted string\"" |> (Regex "\"[^\"]*\"").Match |> string

First function generates a compiler error, the string function is underlined in red. ("This expression was expected to have type Match -> 'a but here has type string")

Second function is fine, no problems.

Is this by design?

MiloDC
  • 2,373
  • 1
  • 16
  • 25

1 Answers1

6

The reason is, your parameter and the call at the end are the same thing. Double backticks are used to escape the name, they are not part of the name.

So in your case that means that ``string`` and string are exactly the same thing, you are trying to pipe into your string parameter. And yes, this is totally by design.

The C# equivalent are @-escaped names, where for example @hello and hello would clash.

Nikon the Third
  • 2,771
  • 24
  • 35
  • 1
    And, in fact, the double-backticks aren't necessary here at all. You could have written `let upper (string : string) = string.ToUpper()` and it would have worked: `upper "foo"` would produce the result `"FOO"`. The only time the double-backticks are **necessary** is if you want to name your parameter by the name of a keyword like `type`, or if you want to include spaces or other normally-illegal punctuation in its name. – rmunn Apr 22 '17 at 07:20