Draft Chapter 2 of "Expert F#": Essential Language Features


[ Note: this post is now out-of-date: drafts of Chapters 2-7 are now available


I’m very glad to announce the availability of an early draft of Chapter 2 of a book on F# which I’m currently in the process of co-authoring.  The projected title of the book is, unabashedly, “Expert F#“. This is one of two F# books planned for publication by Apress in 2007 (having seen early drafts I can say the other one will also be great!)

[ Editors Note: there are a couple of minor issues that readers have spotted with the draft chapter

  • When using the F# Interactive console window with F# 1.1.12 you MUST currently place “;;” on a SEPARATE line, and not at the end of the line as shown in the book.  When using it with Visual Studio you don’t need the “;;” at all.
  • F# Interactive does not print all values in exactly the same way as shown in the book  ]

The draft chapter is a Word document attached to this post, and covers most of the language constructs in tutorial mode, with the exception of object oriented programming, which will be covered in Chapter 3.  (I hope to make a draft of Chapter 3 available fairly soon – if you’d like a very early draft then please contact me directly! )

I trust you will find this a useful resource for learning F# – it has been favourably received by people at MSR Cambridge. We’ll update the draft for minor fixes, though of course the final version will be available in the book.

This is only a draft that has not undergone formal technical or copy editing, so please just ignore egregious mistakes and be patient with poor formatting and dangling symbolic cross-references (for various reasons Apress do not use Word cross-referencing and prefer to do it later in the production process).  Also some Apress fonts may be used, though I have attempted to replace these in the copy circulated here.

Finally, some Word comments indicate where discrepancies exist with the current F# release.




Comments (8)

  1. Song says:

    very intersting,i’ll focus

  2. dhoward says:

    regarding a statement in the draft chapter, there is something I don’t understand. it says

    "in other languages a local “value” is called a local variable. However in F# you can’t change the immediate value of locals after they’ve been initialized, unless the local is explicitly marked as mutable. "

    however, in fsi the following rebinding of a local works without complaint, whereas the global rebind fails with the expected error message.  what am I missing?

    > let test x =

    –     let a = 1

    –     let a = 2

    –     printf "%d %dn" a x

    – ;;

    val test : int -> unit

    > test 1

    – ;;

    2 1

    val it : unit = ()

    > let a = 1

    – let a = 2

    – ;;

     let a = 2


    stdin(142,4): error: FS0037: Duplicate definition of value ‘a’

    stopped due to error


  3. Well, sort of 🙂 One of our most recent scientific users of F# is Darren Platt , head of computational

  4. dsyme says:

    In reply to the above –

    "rebinding" a name to a new value is different to "changing the value itself" – e.g. even in F# Interactive after

    let x = 1

    let y() = x

    let x = 2

    then "y()" will still have the value "1". If you want to really mutate values use

    let mutable x = 1

    let y() = x

    do x <- 2

  5. dhoward says:

    thanks that helps. I suggest you add something like that to the chapter because the original statement is confusing to an imperative language programmer, such as myself, who think in terms of variables as memory locations that contain a value that can change.

  6. Eralp says:

    Thanks For book , It's amazing..I 'll share all of my information about F# with all Turkish programmers at university!.