Lesson 7. Expressions and statements

Expressions and statements are two aspects of programming that we use often, and generally take for granted, but in F# the distinction between the two is much starker than you might be used to. In this lesson, you’ll do the following:

  • Explore the differences between statements and expressions
  • Lean the pros and cons of both
  • See how expressions in combination with the F# type system and compiler can help you write code that’s more succinct as well as easier to reason about

7.1. Comparing statements and expressions

Before we dive in, let’s quickly recap the definitions of statements and expressions. Here are two definitions taken directly from the C# documentation on MSDN—first statements, and then expressions: ...

Get Get Programming with F#: A guide for .NET developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.