Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# - What's the "it" keyword?

Tags:

f#

I am a newb to F#, just began learning it this afternoon.

What I've noticed is that when getting type info via the fsi, I get the following info:

val it : (char list -> string -> string list) = <fun:clo@0>

If I understand correctly, the (char list -> string -> string list) means that the function takes a list of char and returns a function that takes a string and returns a list of string.

However, I don't understand the usage of the "it".

Thanks for any info!

like image 567
Jean Azzopardi Avatar asked Jul 18 '09 14:07

Jean Azzopardi


3 Answers

In the F# interactive command line, "it" is an identifier that gets bound to the last expression evaluated. For example:

> let a = 5;;

val a : int = 5

> a;;
val it : int = 5
> it;;
val it : int = 5
>
like image 195
James Hugard Avatar answered Oct 14 '22 16:10

James Hugard


It's not a keyword. Here's the F# keyword list.

Info on the val keyword:

The val keyword is used to declare a field in a class or structure type without initializing it. Fields declared in this manner are called explicit fields.

[ static ] val [ mutable ] [ access-modifier ] field-name : type-name

So the it normally is the field name.

In the interactive console it's the return value (val) (the name is irrelevant, they just call it "it"):

> System.Console.ReadLine();;
Test
val it : string = "Test"
> it;;
val it : string = "Test"
like image 11
weiqure Avatar answered Oct 14 '22 16:10

weiqure


"it" is sometimes used as a placeholder argument name (for example, arguments to anonymous blocks). It's (no pun intended ;-) just a convention AFAIK.

like image 3
Vinay Sajip Avatar answered Oct 14 '22 14:10

Vinay Sajip