3 F# Syntax Basics

 

This chapter covers

  • Understanding core F# syntax rules
  • Working with Type Inference in F#

Now that you’ve gained a basic understanding of F# tooling and have spent a little time writing some (admittedly simple) F#, it’s time to learn about the core elements of the F# language. Many of the concepts and elements that you learn in this chapter are what I would call “cross-cutting” – they don’t have specific impacts in any one type of application or use case but form the underpinnings of almost everything else in the language. So, it’s important to make sure that you learn these concepts thoroughly. The first two – syntax and type inference – will give you an insight into the structure of the language and the “look-and-feel” of the language, whilst the second half of this chapter will help you understand how you’ll be structuring and composing applications together and building basic routines at a fundamental level.

3.1 F# Syntax Basics

The core syntax rules of a language say a lot about the “feeling” of the language. For example, some languages may have a focus on being highly explicit and verbose (I would, for example, put Java into this category); others may be terse and powerful but require some more investment upfront to understand what’s going on (Haskell perhaps). Others might be lightweight with the intention of “getting out of your way” but not allow you to easily define the rules of what you’re trying to achieve (Go and perhaps Python).

3.1.1 Characteristics of F# syntax

3.1.2 The let Keyword

3.1.3 Scoping

3.2 Type Inference

3.2.1 Benefits of Type Inference

3.2.2 Type Inference Basics

3.2.3 Inferring Generics

3.2.4 Diagnosing unexpected type inference behaviour

3.2.5 Limitations of Type Inference

3.2.6 Criticisms of Type Inference

3.3 Exercise Answers

3.4 Summary

sitemap