Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is "id" literal defined?

Tags:

f#

FsUnit source code contains an unusual definition:

let be = id

FSI output:

val was : ('a -> 'a)

The semantics of the "id" is the parenthesized form of the following statement:

let be x = x

FSI output:

val be : 'a -> 'a

You can see the slight difference: the latter example replaces expression be true with true, while the first syntax would represent it as (true).

What puzzles me is that I can't find any reference to "id" in F# language reference, neither it is described in a "Programming F#" book. Moreover, "id" is not a reserved keyword, I can define assign "id" to something else, and then I no longer can use it in a way that is shown in the first example. So I wonder if there are any F# documents that describe this literal and its semantics.

like image 361
Vagif Abilov Avatar asked Aug 03 '10 12:08

Vagif Abilov


2 Answers

Most of these built-in functions are defined in the FSharp.Core library, Microsoft.FSharp.Core.Operators module.

They're documented on MSDN. Here's id: http://msdn.microsoft.com/en-gb/library/ee353607.aspx

like image 117
Tim Robinson Avatar answered Sep 23 '22 02:09

Tim Robinson


This doesn't look like a literal at all. It looks more like a function. Specifically, guessing by the signature and the name, it looks like the identity function.

like image 25
Jörg W Mittag Avatar answered Sep 24 '22 02:09

Jörg W Mittag