user1002059
user1002059

Reputation: 1525

Two simple F# questions

There are two snippets of F# I would like to understand, but don't know what to google. First:

let ``1+2`` () = .... 

I am guessing this just means "turn the expression into an identifier"? But what is that feature called if I want to refer to it?

Second, what does the character ^ mean when it occurs in a type? I have found several mentions of it, but the explanation always just says "the type is this" rather than "it differs from a type without a 1^1 in that ...". For example:

let inline blah x y = x+y;;
val inline blah :
   ^a ->  ^b ->  ^c
    when ( ^a or  ^b) : (static member ( + ) :  ^a *  ^b ->  ^c)

Many thanks in advance.

Upvotes: 4

Views: 182

Answers (2)

sblom
sblom

Reputation: 27383

  1. I'd probably call that a "quoted identifier" http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/spec.html#_Toc270597387
  2. "Statically resolved type parameter" http://msdn.microsoft.com/en-us/library/dd548046%28VS.100%29.aspx

Upvotes: 4

Brian
Brian

Reputation: 118935

The backquote syntax is indeed just a way to 'quote' arbitrary characters into identifiers, I am not sure if it has a name. It is typically used for e.g.

let ``This Identifier Contains Spaces`` = 42

or

foo.``member``(42)  // 'member' is an F# keyword, but maybe it was the name of some 
                    // method from C# code you're using, so here's a way to call it

The carat indicates a statically resolved type parameter:

http://msdn.microsoft.com/en-us/library/dd548046.aspx

used for ad-hoc overloading/genericity.

Upvotes: 1

Related Questions