Basic values

In F#, every valid value must have a type, and a value of one type may not be bound to a value of another type. We will declare values in F# using the let keyword. For example, refer to the following piece of code:

    // variable expression 
    let x = 10 
    // function expression 
    let add a b = a + b 

As you learn F#, you will initially spend a lot of time getting the F# type checker to accept your programs. Being patient and analyzing the results with the F# type checker eventually helps you program better; you will later realize that the type checker is your best friend. Some rules about type checking are as follows:

  • Every expression has exactly one type
  • When an expression is evaluated, one of the following two things can happen:
    • It could evaluate ...

Get Mastering F# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.